Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can the script putting a gui into a player be wrong?

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.

1 answer

✓ Accepted answer

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.

8 comments

0

Okay, i will try this. somewhat.

0

It didn't work.

0

That isn't very much information to go by. What is the output?

0

I did put the output, that was all the output said, then the typical stack start, same message, stack end.

0

Infact, it is the exact same output, and please explain what you mean by other.Parent is not a players character?

0

If you made the change I suggested, that error is impossible.

0

Im implementing the fix now, if it works, thank you, if it doesn't, thanks for trying.

0

Thank you, that worked! Now, maybe you can naswer something else for me, in a gui frame, i have a problem where i have a button called ShopButton1 inside a frame, but no matter where i put the variable in any script, it says 'ShopButton1 is not a member of Frame' I usually fix this problem by turning that variable into a global variable in a script that i put all global variables in. But it isn't

This discussion is preserved as it was. New answers, comments, and votes are closed.