Why the server keeps saying this (2) when I already set the value(1)? (IT WORKS AT STUDIO, BUT NOT AT ROBLOX ;-;)
(1)
ServerScriptService.LoadMapScript:9: attempt to index global 'LocalPlayer' (a nil value)
(2) "Players" setting script
Players = game:GetService("Players").LocalPlayer
Error script part
PlayerGui = Players.PlayerGui
Others: Whole script
wait(10) print("LoadMapScript activated") replicatedStorage = game:GetService("ReplicatedStorage") serverstorage = game:GetService("ServerStorage") Players = game:GetService("Players").LocalPlayer win = game.ServerStorage.values:WaitForChild("win") win.Value = 2 PlayerGui = Players.PlayerGui GUIname = PlayerGui.MapName:WaitForChild("Name") GUIcreator = PlayerGui.MapName:WaitForChild("Creator") gamelocation = CFrame.new(math.random(51.5,58.5),2.5,math.random(128,136)) lobbylocation = CFrame.new(math.random(4065.5,4114.5),6.5,math.random(83.5,182.5)) function tptogame() if Players.Character and Players.Character:FindFirstChild("HumanoidRootPart") then Players.Character.HumanoidRootPart.CFrame = gamelocation end end function tptolobby() if Players.Character and Players.Character:FindFirstChild("HumanoidRootPart") then Players.Character.HumanoidRootPart.CFrame = lobbylocation end end function unloadMap() if workspace:FindFirstChild("Map") then workspace.Map:Destroy() end end function onPlayerAdded(player) print(player.Name .. " has entered the game") end --When a player joins, call the onPlayerAdded function game.Players.PlayerAdded:connect(onPlayerAdded) --Call onPlayerAdded for each player already in the game for _,player in pairs(game.Players:GetPlayers()) do onPlayerAdded(player) end -- 0 Test Map repeat if win.Value == 2 then print("Game Ended") tptolobby() unloadMap() win.Value = 1 GUIname.Text = "Game Ended" GUIcreator.Text = "GG!" print("Game Ended") wait(3) GUIname.Text = "Interveral" GUIcreator.Text = "Have a nice rest!" print("Interveral") wait(30) GUIname.Text = "Selecting Map..." GUIcreator.Text = ":o" print("Selecting Map") wait(math.random(1,4)) mapvalue = math.random(0,0) if mapvalue == 0 then -- Test Map print("Test Map") GUIname.Text = "Loading Map..." game.ReplicatedStorage.Maps["Test Map"]:Clone().Parent = workspace game.Workspace["Test Map"].Name = "Map" GUIname.Text = "Test Map" tptogame() GUIcreator.Text = "By chatiii" end else wait(0.5) end until nil
You have to have the script in a local script because server scripts can not access that directly, you also have to have the script inside the starter player scripts so that you can use it.