Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script only one IntValue to leaderstats?

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)

1 comment

0

the reason why is because ur making instance.new money inside of the toal.Changed function

1 answer

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)

4 comments

0

line 4

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

0

dident work

0

Make sure it’s a LocalScript, inside of StarterPlayerScripts

This discussion is preserved as it was. New answers, comments, and votes are closed.