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.
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.