So... in my game I used the leaderboard as currency ("Points"). Then I made a Part that if you step on it it will check if you have enough then subtract the price from your points. If you don't have enough, it would clone a GUI from Server Storage and send it (change the parent) into the PlayerGui in Players. It works perfectly in Studio but doesn't work in ROBLOX Player. Why is this?
This is the code:
script.Parent.Touched:connect(function()
for _,Player in pairs(game.Players:GetPlayers()) do
if Player:FindFirstChild("leaderstats") then
if Player.leaderstats.Points.Value >= script.Parent.Price.Value then
Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - script.Parent.Price.Value
game.ServerStorage.Tools["Blue Torch"]:Clone().Parent = game.Players.LocalPlayer.Backpack
else
game.ServerStorage.GUI["Not enough"]:Clone().Parent = game.Players.LocalPlayer.PlayerGui
wait(5)
game.Players.LocalPlayer.PlayerGui["Not enough"]:Destroy()
end
end
end
end)

1 comment
It's a touched function. I'm pretty sure data is loaded farrrrr before you would walk around and touch a part. Good thought but inaccurate.