My program should work fine, but the output says "Workspace.map.teleporter3.teleport.Script:10 attempt to index global 'player' (a nil value) "
touched = false button = script.Parent teleportergui = script.teleporterservice1 function onTouch(other) if other.Parent.Name == "teleporter3" then --this is because it keeps thinking the model it's in is the character... touched = false else player = game.Players:GetPlayerFromCharacter(other.Parent) local tele2gui = teleportergui:clone() tele2gui.Parent = player.PlayerGui wait(5) tele2gui:Destroy() touched = true wait (10) touched = false end end button.Touched:connect(onTouch)
can anyone tell me where this went wrong? Please, any questions, tell me.
This means that player
is nil
.
Looking at how you compute player
, the cause is that other.Parent
is not a player's character (hence GetPlayerFromCharacter
returns nil
).
Just check that player
is not nil
before continuing:
if player then local telegui .... ... end
Also note that it's best practice to check other.Parent
to not be nil
before using it, since in the case of bullets, it frequently will e.