Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LocalPlayer Issues in ServerScript?

Asked by 6 years ago
Edited 6 years ago

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)

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

1 answer

Log in to vote
0
Answered by
CootKitty 311 Moderation Voter
6 years ago

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.

Ad

Answer this question