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)

4 comments
When you test in studio, everything runs locally, and you can't use LocalPlayer in a serverscript
I have found that out so I am looking for an alternative way to get the player.
why don' you just make the script local
As in convert it to local or just copy and paste everything into a local script?