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

Why doesnt this script teleport the player?

I have made the following script, it needs to teleport the player from one world to another, however, it does not work. This script is a localscript. The reason for all of the different things is that the parts lie inside a model, named DannebrogStill.

local TeleportService = game:GetService("TeleportService")
local placeID_1 = 751068488
local player = game.Players.LocalPlayer

while true do
game.Workspace.DannebrogStill.End.Touched:Connect(function(part)
	if part.Parent.HumanoidPlayer then
		TeleportService:Teleport(placeID_1, player)
	end 
end)

game.Workspace.DannebrogStill.Head.Touched:Connect(function(part)
	if part.Parent.HumanoidPlayer then
		TeleportService:Teleport(placeID_1, player)
	end 
end)

game.Workspace.DannebrogStill.Middle.Touched:Connect(function(part)
	if part.Parent.HumanoidPlayer then
		TeleportService:Teleport(placeID_1, player)
	end 
end)

game.Workspace.DannebrogStill.NearMiddle.Touched:Connect(function(part)
	if part.Parent.HumanoidPlayer then
		TeleportService:Teleport(placeID_1, player)
	end 
end)

game.Workspace.DannebrogStill.Second.Touched:Connect(function(part)
	if part.Parent.HumanoidPlayer then
		TeleportService:Teleport(placeID_1, player)
	end 
end)

game.Workspace.DannebrogStill.Third.Touched:Connect(function(part)
	if part.Parent.HumanoidPlayer then
		TeleportService:Teleport(placeID_1, player)
	end 
end)

game.Workspace.DannebrogStill.Torso.Touched:Connect(function(part)
	if part.Parent.HumanoidPlayer then
		TeleportService:Teleport(placeID_1, player)
	end 
end)
end

5 comments

0

What doesn't work? Does it give an error or anything?

0

Can you post a screenshot of the parts?

0

can you reply with the output?

0

ye that to

0

thats for a localscript use something like game.Players:GetPlayerFromCharacter(part.Parent.HumanoidPlayer) but you should also define the HumanoidPlayer

2 answers

Try this, if this doesnt work. Reply with the error.

local TeleportService = game:GetService("TeleportService")
local placeID_1 = 751068488
local player = game.Players.LocalPlayer

while wait() do
	game.Workspace.DannebrogStill.End.Touched:Connect(function(part)
	    if part.Parent.HumanoidPlayer then
	        TeleportService:Teleport(placeID_1, player)
	    end 
	end)
	
	game.Workspace.DannebrogStill.Head.Touched:Connect(function(part)
	    if part.Parent.HumanoidPlayer then
	        TeleportService:Teleport(placeID_1, player)
	    end 
	end)
	
	game.Workspace.DannebrogStill.Middle.Touched:Connect(function(part)
	    if part.Parent.HumanoidPlayer then
	        TeleportService:Teleport(placeID_1, player)
	    end 
	end)
	
	game.Workspace.DannebrogStill.NearMiddle.Touched:Connect(function(part)
	    if part.Parent.HumanoidPlayer then
	        TeleportService:Teleport(placeID_1, player)
	    end 
	end)
	
	game.Workspace.DannebrogStill.Second.Touched:Connect(function(part)
	    if part.Parent.HumanoidPlayer then
	        TeleportService:Teleport(placeID_1, player)
	    end 
	end)
	
	game.Workspace.DannebrogStill.Third.Touched:Connect(function(part)
	    if part.Parent.HumanoidPlayer then
	        TeleportService:Teleport(placeID_1, player)
	    end 
	end)
	
	game.Workspace.DannebrogStill.Torso.Touched:Connect(function(part)
	    if part.Parent.HumanoidPlayer then
	        TeleportService:Teleport(placeID_1, player)
	    end 
	end)
end

I suggest making it a script instead of local script. If you do, I think this code is what you are looking for.

(BTW this teleports the player to a place when they touch it. You will have to modify the gameID)


local TeleportService = game:GetService("TeleportService")
local gameID = 3869185466 --put place id here
 
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        TeleportService:Teleport(gameID, player)
    end
end
 
script.Parent.Touched:connect(onTouched)

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