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

How Do I Teleport only 1 player?

Asked by 3 years ago

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.

0
Where's your script xXLegendGamerz16Xx 231 — 3y
0
i don't have it :( frowerexmet 0 — 3y

2 answers

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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)
Ad
Log in to vote
0
Answered by
zomspi 541 Moderation Voter
3 years ago
Edited 3 years ago

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.

0
Edit: I was using the C# way to add comments, changing from "//" to "--" zomspi 541 — 3y
0
Another edit I messed up the code fixed it now zomspi 541 — 3y
0
ok thz ill check it out frowerexmet 0 — 3y
0
it doesn't seem to be working frowerexmet 0 — 3y
View all comments (4 more)
0
10:40:04.130 Workspace.Part.Script:7: invalid argument #1 (CFrame expected, got Instance) frowerexmet 0 — 3y
0
part.CFrame xXLegendGamerz16Xx 231 — 3y
0
plr.Parent.HumanoidRootPart.CFrame = part.CFrame + CFrame.new(0, 1, 0) xXLegendGamerz16Xx 231 — 3y
0
again, i doesn't!t work :8 frowerexmet 0 — 3y

Answer this question