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)
Clients cannot access ServerStorage, and you are using game.Players.LocalPlayer meaning it's a local script in the client. You will have to send a request to a server script with RemoteEvents so that the server can clone the guy to other players.
It's possible you need,
Player:WaitForDataReady()
to ensure the player is fully loaded in before you start accessing their values. If that doesn't work, you could try putting it into a Localscript, I've made some modifications below
script.Parent.Touched:connect(function() local Player = game.Players.LocalPlayer 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 = Player.Backpack else game.ServerStorage.GUI["Not enough"]:Clone().Parent = Player.PlayerGui wait(5) Player.PlayerGui["Not enough"]:Destroy() end end end)