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

ServerScriptService.Lessons:5: attempt to index field 'LocalPlayer' (a nil value)?

Asked by
Filipalla 504 Moderation Voter
8 years ago
Edited 8 years ago
while true do wait(5)
    lessons=math.random(1,5)
    if lessons == 1 then
        --swimming
        game:WaitForChild("ServerStorage").Lessons:clone().Parent = game.Players.LocalPlayer.PlayerGui
        game:WaitForChild("Players").LocalPlayer.PlayerGui.Lessons.Swimming.Visible = true
        wait(60)    
    end
end

and i get the error ServerScriptService.Lessons:5: attempt to index field 'LocalPlayer' (a nil value) how did i fix it? Edit now geting this Infinitie yield possible on "Game:WaitForChild"

0
normal script Filipalla 504 — 8y
0
You can not use LocalPlayer in a Server Script. You can only use LocalPlayer in a LocalScript. M39a9am3R 3210 — 8y
0
helped alot Filipalla 504 — 8y
0
but still not working Filipalla 504 — 8y

1 answer

Log in to vote
0
Answered by
itsJooJoo 195
8 years ago

Problem

LocalPlayer doesn't exist in ServerScripts, but ServerStorage doesn't exist in LocalScripts.

Solution

Use the PlayerAdded function to find the player

Final Script

Note: This is a Server Script

game:GetService("Players").PlayerAdded:connect(function(player)
    while true do
        wait(5)
        lessons=math.random(1,5)
            if lessons == 1 then
            --swimming
            game:WaitForChild("ServerStorage").Lessons:clone().Parent = player.PlayerGui
            player.PlayerGuiLessons.Swimming.Visible = true
        wait(60)    
        end
    end
end)
0
thx bro ill see if it works Filipalla 504 — 8y
Ad

Answer this question