I don't get what is causing this error. I'm new to scripting and only recently have started to get the hang of it. I get this error when attempting to write scripts a lot. It'd be nice if I knew in general what causes this error.
PLAY = script.Parent PLAY.MouseButton1Down:connect(function() PLAY.Text = "ENJOY! :D" wait(0.1) PLAY.Text = "You will spawn in 3 seconds..." wait(3) game.Players.Player.PlayerGui.ScreenGui:Remove() wait(0.2) game.StarterPlayer.CameraMode.LockFirstPerson
NOTE: "PLAY" is the name of my TextButton
In your script you made a function a Variable which won't work, you also added game.Players.Player.PlayerGui
, player in this case, would be nil, because when you joined the server there would be no player
so what would we do? We would use game.Players.LocalPlayer
It finds the LocalPlayer which is you, But please note that LocalPlayer
Only works in a LocalScript.
local play=script.Parent plr=game.Players.LocalPlayer chr=plr.Character--the Character of the player(found in Workspace) play.Text="HELLO"--Change play.MouseButton1Down:connect(function()--functions don't make a good variable wait(.1)--or 0.1 play.Text="You will respawn in 3 seconds" wait(3) plr.PlayerGui.ScreenGui:remove()--remove once clicked wait(.2) plr.CameraMaxZoomDistance=0.5 plr.CameraMinZoomDistance=0.5 chr.Humanoid.Died:connect(function() plr.CameraMaxZoomDistance=400 plr.CameraMinZoomDistance=0.5 end) end)
Ok so what I've added here is your play
gui/button, then the LocalPlayer that I was talking about earlier, as you can see I added plr.CameraMaxZoomDistance=0.5
instead of using game.StarterPlayer, its because StarterPlayer, sets it up before the player ever joins and when the server is running it can not be changed again(when on server). I added a chr.Humanoid.Died
function so that it won't be in FPS mode when you respawn.
please note that this is in a LocalScript If there are any errors just Comment below.
I fixed that but the error is actually coming from the last end that it is requiring me to add.
Here is the new script:
PLAY = script.Parent
PLAY.MouseButton1Down:connect(function() PLAY.Text = "ENJOY! :D" -- end)
wait(0.1)
PLAY.Text = "You will spawn in 3 seconds..."
wait(3)
game.Players.Player.PlayerGui.ScreenGui:Remove()
wait(0.2)
game.StarterPlayer.CameraMode.LockFirstPerson
end
The error remained the same.