Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script only one IntValue to leaderstats?

Asked by
danglt 185
5 years ago

when i have this script in ServerScriptService it only adds "Total"

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"
 local Toal = Instance.new("IntValue",leader)
 Toal.Name = "Total"
 Toal.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Toal.Value)
 Toal.Changed:connect(function()
  ds:SetAsync(player.UserId, Toal.Value)

local Money = Instance.new("IntValue",leader)
 Money.Name = "Money"
 Money.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Money.Value)
 Money.Changed:connect(function()
  ds:SetAsync(player.UserId, Money.Value)
 end)
end)
end)

game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Total.Value)
ds:SetAsync(player.UserId, player.leaderstats.Money.Value)
end)
0
the reason why is because ur making instance.new money inside of the toal.Changed function HappyTimIsHim 652 — 5y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Your issue is being caused because of the Second Argument of `Instance.new() being deprecated; no longer supported. This can be fixed easily by writing this instead

game.Players.PlayerAdded:Connect(function(player)
   local leader = Instance.new("Folder"); leader.Parent = player
   leader.Name = "leaderstats"
   local Toal = Instance.new("IntValue"); Total.Parent = leader
   Toal.Name = "Total"
   local Money = Instance.new("IntValue"); Money.Parent = leader
   Money.Name = "Money"
end)
0
line 4 DinozCreates 1070 — 5y
1
excuse me but are you sure about this? Even though it's deprecated and shouldn't be used, it still works, at least AFAIK, also he uses :connect() lol Elixcore 1337 — 5y
0
dident work danglt 185 — 5y
0
Make sure it’s a LocalScript, inside of StarterPlayerScripts Ziffixture 6913 — 5y
Ad

Answer this question