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

How Do I Teleport only 1 player?

So i am trying to make a part that checks the amount of players touching it. If there's only 1 player touching, its gonna teleport the player to another part. I Spent hours on it and messed up so i really need help! Can Someone Help Me ? I appreciate.

2 comments

0

Where's your script

0

i don't have it :(

2 answers

This is a modified version of zomspi's script.

local part = workspace:WaitForChild("Part1") -- Directory of your part, usually script.Parent
local part2tp = workspace:WaitForChild("Part2") -- Directory of the part you want to teleport to
local NumOfPlayersTouching = 0 

part.Touched:Connect(function(otherPart)
	local Player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if not Player then return end -- It was not a player that touched the part
	if NumOfPlayersTouching == 0 then
		Player.Character.HumanoidRootPart.CFrame = CFrame.new(part2tp.Position) * CFrame.new(0,1,0)
	end
	NumOfPlayersTouching += 1
end)

part.TouchEnded:Connect(function()
	NumOfPlayersTouching -= 1
end)

Ok I'm sorry if this is not correct because I haven't coded for a little while but I would assume something like this would work:

local part = part -- Directory of your part, usually script.Parent
local part2tp = part2tp -- Directory of the part you want to teleport
local value = value -- This is where you make a int value (or number value) called whatever you want and direct it here

part.Touched:Connect(function(plr)
if value.Value == 0 then
plr.Parent.HumanoidRootPart.CFrame = part + CFrame.new(0, 1, 0)
value.Value += 1
else
value.Value += 1
end

part.TouchEnded:Connect(function()
value.Value -= 1
end

See if this works.

8 comments

0

Edit: I was using the C# way to add comments, changing from "//" to "--"

0

Another edit I messed up the code fixed it now

0

ok thz ill check it out

0

it doesn't seem to be working

0

10:40:04.130 Workspace.Part.Script:7: invalid argument #1 (CFrame expected, got Instance)

0

part.CFrame

0

plr.Parent.HumanoidRootPart.CFrame = part.CFrame + CFrame.new(0, 1, 0)

0

again, i doesn't!t work :8

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