So, I do not know if I should be using a server script or local script. I have script, it does not work.
I want the player to teleport to part2 if they touch part1. The player should not be able to touch part1 to get to part2. Here is my script:
if script.Parent.IsTouched == true then game.Workspace.Player.Position = game.Workspace.Part2.Position end
function onTouched(hit) local human = hit.Parent:FindFirstChild("HumanoidRootPart") if hit then human.CFrame = game.Workspace.Part2.CFrame end end script.Parent.Touched:connect(onTouched)
This should be in the script of the Part that you want to be touched. Part2 should be renamed to the name of the part you want teleported to.
Try this:
script.Parent.Touched:Connect(function(part) local char = part:FindFirstAncestorWhichIsA("Model") local dest_part = workspace:FindFirstChild("Part2") if char and dest_part then local plr = game:GetService("Players"):GetPlayerFromCharacter(char) local dest = dest_part.CFrame if plr and dest then dest = dest + CFrame.new(0, 3.5, 0) if dest then char:SetPrimaryPartCFrame(dest) end end end end)