Read this: You should learn more about instance.new, leaderstats, datastore remoteevents... If you just copy and paste this and dont learn about it you will dont understand anything about this
You should not use remote here cuz game.Players is server-sided so you can change things in the players without localscript.
i'll will try my best to guide you through this.(sry for my bad english ;P xP)
I dont know what you want "Tries" for and i dont see it beeing used in the script so i'll skip it.
At the beginning you should create a datastore for each instance.new
xps = game:GetService("DataStoreService"):GetDataStore("xps")
levels = game:GetService("DataStoreService"):GetDataStore("levels")
Excap = game:GetService("DataStoreService"):GetDataStore("Excap")
I wont explain this part much cuz you should now this:
I'll explain GetAsync later
game.Players.PlayerAdded:Connect(function(player)
stats = Instance.new("Folder", player)
stats.Name = "leaderstats"
xp = Instance.new("IntValue", leaderstats)
xp.Name = "XP"
xp.Value = xps:GetAsync(player.UserId) or 0
level = Instance.new("IntValue", leaderstats)
level.Name = "Level"
level.Value = levels:GetAsync(player.UserId) or 1
excap = Instance.new("IntValue", leaderstats)
excap.Name = "Excap"
excap.Value = excaps:GetAsync(player.UserId) or 500
end)
Now lets save the data if the values change
This will be inside the game.Players.PlayerAdded:Connect(function(player)
Set/GetAsync uses to set or load data. in this case we set the data to the players userid and the data we will set is xp,level and excap. The GetAsync abow will get the data from the player who joined. If the player doesnt have a data it will be set to the thing after or
xp.Value.Changed:Connect(function()
xps:SetAsync(player.UserId, xp.Value)
end)
level.Value.Changed:Connect(function()
levels:SetAsync(player.UserId, level.Value)
end)
excap.Value.Changed:Connect(function()
excaps:SetAsync(player.UserId, excap.Value)
end)
and now lets add your calculations inside the game.Players.PlayerAdded:Connect(function(player) aswell.
We dont need these ;
if xp.Value >= excap.Value then
if level.Value < 100 then
level.Value = level.Value + 1
xp.Value = xp.Value-excap.Value
excap.Value = excap.Value * 2
end
end
if level.Value == 100 and xp.Value ~= 0 then
xp.Value = 0
end
So in the end it will be something like this
xps = game:GetService("DataStoreService"):GetDataStore("xps")
levels = game:GetService("DataStoreService"):GetDataStore("levels")
excaps = game:GetService("DataStoreService"):GetDataStore("Excaps")
game.Players.PlayerAdded:Connect(function(player)
stats = Instance.new("Folder", player)
stats.Name = "leaderstats"
xp = Instance.new("IntValue", leaderstats)
xp.Name = "XP"
xp.Value = xps:GetAsync(player.UserId) or 0
level = Instance.new("IntValue", leaderstats)
level.Name = "Level"
level.Value = levels:GetAsync(player.UserId) or 1
excap = Instance.new("IntValue", leaderstats)
excap.Name = "Excap"
excap.Value = excaps:GetAsync(player.UserId) or 500
xp.Value.Changed:Connect(function()
xps:SetAsync(player.UserId, xp.Value)
end)
level.ValueChanged:Connect(function()
levels:SetAsync(player.UserId, level.Value)
end)
excap.ValueChanged:Connect(function()
excaps:SetAsync(player.UserId, excap.Value)
end)
if xp.Value >= excap.Value then
if level.Value < 100 then
level.Value = level.Value + 1
xp.Value = xp.Value-excap.Value
excap.Value = excap.Value * 2
end
end
if level.Value == 100 and xp.Value ~= 0 then
xp.Value = 0
end
end)
4 comments
connect is deprecated. Use Connect instead.
im not super sure what is going on cuz im not that good, but i think u should change XP.Changed blah blah blah to XP.Changed:Connect(XPChange)
it's XP.Value.Changed (you forgot the .Value, thus checking for the instance rather than the XP value)
(also put the XPChange function as a local function at the top of the script because you can't call it before it gets initialized)