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

Fail at the teleport script?

Asked by 10 years ago
function onClicked(click)
    local player = game.Players:GetPlayerFromCharacter(click.Parent)
    if player then
        game:GetService("TeleportService"):Teleport(116211000, player)
    end
end

script.Parent.MouseButton1Click:connect(onClicked)

I know the problem is in the line 2, show me what!

2 answers

Log in to vote
1
Answered by 10 years ago
function onClicked()
    local player = script.Parent
    repeat player = player.Parent until player:IsA('Player')
    if player then
        game:GetService("TeleportService"):Teleport(116211000, player)
    end
end

script.Parent.MouseButton1Click:connect(onClicked)

Try this, it keeps going through the parents of the script until it reaches a player, then it will teleport them.

Ad
Log in to vote
0
Answered by 10 years ago

Please read this thread for how to use the TeleportService; http://wiki.roblox.com/index.php?title=TeleportService_Guide

And heres how you'd do it with a TextButton;

repeat wait(0)until game:FindService"Players"and game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild"Humanoid"and game.Players.LocalPlayer:GetMouse()and game.Players.LocalPlayer:FindFirstChild"PlayerGui"

script.Parent.MouseButton1Click:connect(function()
if game:FindService("TeleportService")then
game:GetService("TeleportService"):Teleport(116211000,game.Players.LocalPlayer)
end end)

Hope this helped!

0
forgot "and" after finding "Players" service. ImageLabel 1541 — 10y
0
Oh, thanks for pointing that out. TheeDeathCaster 2368 — 10y

Answer this question