Hello! So I have a script that runs when a GUI is clicked however, it works in studio but ingame, I looked at the dev console and it says that there is an error on line 8 with LocalPlayer. What am I doing wrong? Also, I now realize that this will only work in a local script so what can I use to replace game.Players.LocalPlayer?
local Button = script.Parent Frame = script.Parent.Parent.Parent EditBlock = script.Parent.Parent.Parent.Parent OldOven = script.Parent.Parent.Parent.Parent.OldOven NewOven = script.Parent.Parent.Parent.Parent.Oven function onClick() if game.Players.LocalPlayer.leaderstats.Money.Value >= 250 then Frame.Enabled = false EditBlock.Transparency = 1 local user = game.Players:GetPlayerFromCharacter(game.Players.LocalPlayer.Character) --get player from touching human local stats = user:findFirstChild("leaderstats") --Find moneyholder local cash = stats:findFirstChild("Money") --Get money cash.Value = cash.Value -250 OldOven:Destroy() NewOven.PartOne.Transparency = 0 NewOven.PartTwo.Transparency = 0 else print("Not enough money!") end end Button.MouseButton1Click:connect(onClick)
LocalPlayer doesn't work in a ServerScript.
If you don't have FE on, I guess you could simply use a LocalScript
Otherwise, you need to change the leaderstats on the server, else they won't replicate to other users and it'll be impossible to ever save the leaderstats.