this script works perfectly in studio, but when i test on a server. Whats wrong with it?
game.Players.PlayerAdded:connect(function(player) local leaderstat = Instance.new("Model") leaderstat.Parent = player leaderstat.Name = "leaderstats" local ROBUX = Instance.new("IntValue") ROBUX.Name = "CashDonated" ROBUX.Parent = game.Players.LocalPlayer.leaderstats ROBUX.Value = 0 local PlayTime = Instance.new("IntValue") PlayTime.Parent = leaderstat PlayTime.Value = 0 PlayTime.Name = "Play Time" local i = 0 while true do i = i + 1 PlayTime.Value = i wait(1) end end)
game.Players.PlayerAdded:connect(function(player) local leaderstat = Instance.new("Model") leaderstat.Parent = player leaderstat.Name = "leaderstats" local ROBUX = Instance.new("IntValue") ROBUX.Name = "CashDonated" ROBUX.Parent = leaderstat ROBUX.Value = 0 local PlayTime = Instance.new("IntValue") PlayTime.Parent = leaderstat PlayTime.Value = 0 PlayTime.Name = "Play Time" local i = 0 while true do i = i + 1 PlayTime.Value = i wait(1) end end)
You didn't have to refer to LocalPlayer in a server script. Only LocalScript
can refer to LocalPlayer. Also, you didn't need to put it like that, the leaderstats was already parented to player so it would've been faster to put it like this:
ROBUX.Parent = leaderstat
Full script:
game.Players.PlayerAdded:connect(function(player) local leaderstat = Instance.new("Model") leaderstat.Parent = player leaderstat.Name = "leaderstats" local ROBUX = Instance.new("IntValue") ROBUX.Name = "CashDonated" ROBUX.Parent = leaderstat ROBUX.Value = 0 local PlayTime = Instance.new("IntValue") PlayTime.Parent = leaderstat PlayTime.Value = 0 PlayTime.Name = "Play Time" local i = 0 while true do i = i + 1 PlayTime.Value = i wait(1) end end)