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

Fail at the teleport script?

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

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.

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!

2 comments

0

forgot "and" after finding "Players" service.

0

Oh, thanks for pointing that out.

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