Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

0
Okay, i will try this. somewhat. rollercoaster57 65 — 10y
0
It didn't work. rollercoaster57 65 — 10y
0
That isn't very much information to go by. What is the output? BlueTaslem 18071 — 10y
0
I did put the output, that was all the output said, then the typical stack start, same message, stack end. rollercoaster57 65 — 10y
View all comments (4 more)
0
Infact, it is the exact same output, and please explain what you mean by other.Parent is not a players character? rollercoaster57 65 — 10y
0
If you made the change I suggested, that error is impossible. BlueTaslem 18071 — 10y
0
Im implementing the fix now, if it works, thank you, if it doesn't, thanks for trying. rollercoaster57 65 — 10y
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 rollercoaster57 65 — 10y
Ad

Answer this question