Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalPlayer Issues in ServerScript?

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

0

When you test in studio, everything runs locally, and you can't use LocalPlayer in a serverscript

0

I have found that out so I am looking for an alternative way to get the player.

0

why don' you just make the script local

0

As in convert it to local or just copy and paste everything into a local script?

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.