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"
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)