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

Returning player click on a gui and teleporting them, why doesn't it work?

Asked by 9 years ago

So, when you step into a door, this gui is meant to show up. When you click the button, you then get teleported.

GUI Script

function onClick(mouse)
    local player = game.Players:GetPlayerFromCharacter(onClick.Parent)
    if player then
        game:GetService("TeleportService"):Teleport(327607038, player)
    end
end

script.Parent.MouseButton1Click:connect(onClick)

Door Script

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        player.StarterGui.Teleport.Visible = true
    end
end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by 9 years ago

Gui Script

function onClick()
        game:GetService("TeleportService"):Teleport(327607038, game:GetService("Players").LocalPlayer)
    end
script.Parent.MouseButton1Click:connect(onClick)

Door Script

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        player.PlayerGui.Teleport.Visible = true
    end
end
script.Parent.Touched:connect(onTouched)

Try that. That is assuming that the Gui script is a LocalScript.

Ad

Answer this question