· 5 years ago · Jun 05, 2020, 03:02 PM
1--/V
2--Services
3local RS = game:GetService("ReplicatedStorage")
4local Players = game:GetService("Players")
5local DataStoreService = game:GetService("DataStoreService")
6
7--Rewmotes
8local Remote = RS:WaitForChild("RemoteEvent")
9
10--Datastore Vars
11local DataStoreManager = require(script.DataStoreManager)
12local DataStoreForItems = DataStoreService:GetDataStore("ItemsDataStoreF")
13local DataStoreForItemsKey = "SecretKey-"
14local PlayerInventory = {}
15
16--Stats and levels vars
17local LevelUI = script:WaitForChild("LevelUI")
18
19--Tables
20local StatsDebounce = {}
21
22--Default increments for stats
23local DurabilityDefaultIncrement = 1
24local StrengthDefaultIncrement = 1
25local LevelDefaultIncrement = 1
26
27--Wait time between each trigger (Stats)
28local WaitTimeStat = 1 --Not added
29
30game.Players.PlayerAdded:Connect(function(Player)
31
32 --Create Player Stats [Coins, etc] and retrieve their data ((Replace 0 for data from datastore))
33 local Leaderstats = Instance.new("Folder")
34 Leaderstats.Name = "Stats"
35 Leaderstats.Parent = Player
36
37 local Level = Instance.new("IntValue")
38 Level.Name = "Level"
39 Level.Value = 0
40 Level.Parent = Leaderstats
41
42 local Strength = Instance.new("IntValue")
43 Strength.Name = "Strength"
44 Strength.Value = 0
45 Strength.Parent = Leaderstats
46
47 local Durability = Instance.new("IntValue")
48 Durability.Name = "Durability"
49 Durability.Value = 0
50 Durability.Parent = Leaderstats
51
52 Player.CharacterAdded:Connect(function(Character)
53
54 local Head = Character:FindFirstChild("Head")
55
56 local LevelClone = LevelUI:Clone()
57 LevelClone.Adornee = Head
58 LevelClone.Parent = Head
59
60 end)
61
62 --Retrieve Player Data for Items
63
64-- local a = DataStoreManager.RetrievePlayerData(Player, DataStoreForItems, DataStoreForItemsKey, PlayerInventory)
65
66 --
67
68-- PlayerInventory = s
69
70
71end)
72
73
74local function UpdateHeadLevel(Player, Level)
75
76 if Player.Character.Head:FindFirstChild("LevelUI") then
77
78 local LvlUI = Player.Character.Head:FindFirstChild("LevelUI")
79
80 LvlUI.Level.Text = "Level: "..Level.Value
81
82 end
83end
84
85Remote.OnServerEvent:Connect(function(Player, Args)
86
87 print("Fired by "..Player.Name)
88
89 if Args[1] == "Durability" then
90
91 if not StatsDebounce[Player.Name] then
92
93 --Avoid exploiting
94 table.insert(StatsDebounce, Player.Name)
95
96 local DurStat = Player:FindFirstChild("Stats"):FindFirstChild("Durability")
97
98 if DurStat then
99
100 DurStat.Value = DurStat.Value + DurabilityDefaultIncrement
101
102 local Level = Player.Stats.Level
103
104 Level.Value = Level.Value + LevelDefaultIncrement
105
106 UpdateHeadLevel(Player, Level)
107
108 print(Player.Name.." now has "..DurStat.Value)
109
110
111 else
112 error("Stat not found: Durability")
113 end
114
115 end
116
117
118 elseif Args[1] == "Strength" then
119
120 if not StatsDebounce[Player.Name] then
121
122 --Avoid exploiting
123 table.insert(StatsDebounce, Player.Name)
124
125 local StreStat = Player:FindFirstChild("Stats"):FindFirstChild("Strength")
126
127 if StreStat then
128
129 StreStat.Value = StreStat.Value + StrengthDefaultIncrement
130
131 local Level = Player.Stats.Level
132
133 Level.Value = Level.Value + LevelDefaultIncrement
134
135 UpdateHeadLevel(Player, Level)
136
137 print(Player.Name.." now has "..StreStat.Value)
138
139
140 else
141 error("Stat not found: Strength")
142 end
143
144 end
145
146 end
147
148
149end)