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

How do I fix this error on line 5? LocalPlayer = nil value / player = nil value

Asked by 5 years ago
Edited 5 years ago

https://gyazo.com/c868fe5722917c1c6cef3c335da43b50 https://gyazo.com/9cad2185947b4ce68d07aef6ba8f66f1 http://prntscr.com/mmuopt https://gyazo.com/03419319048d4ecb74d4d7a82b8eb3f5

When walking up to the stage1 brick it does nothing. It doesn't show the gui and make it visible please help. There is an error on line 5. Please Help.

script.Parent.Touched:Connect(function()
    local player = game.Players.LocalPlayer
    if player.leaderstats.Stage.Value <= 0 then
    player.PlayerGui.stage.stage1.Visible = true
    elseif player.leaderstats.Stage.Value >= 0 then
        game.Workspace.stage1door:Destroy()
    end
end)
0
is script a localscript? Miniller 562 — 5y
0
^ sonysunny 36 — 5y
0
no KnownC0mmunity 9 — 5y
0
Then that's the problem. It must be a localscript, if you want to detect the leaderstats.Stage, except if you use RemoteEvents. Miniller 562 — 5y
View all comments (9 more)
0
Can u use a localscript instead of an remoteevent KnownC0mmunity 9 — 5y
0
Yes you can. But that would cause some issues (example a script tried to call the GUI but its local). sonysunny 36 — 5y
0
You can only call :FireServer() from a localscript. sonysunny 36 — 5y
0
its not working still KnownC0mmunity 9 — 5y
0
Your trying to get a localplayer from a script. Use :GetPlayerFromCharacter() and it should work. sonysunny 36 — 5y
0
k let me try KnownC0mmunity 9 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Please make sure that this is located inside of a LocalScript!

I'm assuming you know how to define a part from inside of the workspace. So make a localscript inside of StarterPlayer > StarterPlayerScripts

Inside of this script you can put the following code, Where it says "PARTNAME" on line one, put your part.

local Part = game:GetService("Workspace"):FindFirstChild("PARTNAME")
Part.Touched:Connect(function()
    local player = game.Players.LocalPlayer
    if player.leaderstats.Stage.Value <= 0 then
        player.PlayerGui.stage.stage1.Visible = true
    elseif player.leaderstats.Stage.Value >= 0 then
        game.Workspace.stage1door:Destroy()
    end
end)

If this helped you then please mark it as the solution!

Ad
Log in to vote
0
Answered by 5 years ago

Why is this not answered! Someone already said it must be a local script to find a localplayer!

Answer this question