Forcing Player to Move on Touch

Hey there!
I have a script that forces a player to move to a certain point, but I don’t know how to modify it to only work when the player touches a certain part. Here’s the script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.Humanoid:MoveTo(Vector3.new(52.204, 3.882, 14.037))
		wait()
		script.Disabled = true
	end)
end)
local Players = game:GetService("Players")

local touchPart = workspace.Part -- Part path here (can be "script.Parent" if the script is inside the part you want to touch)
touchPart.Touched:Connect(function(touched)
	local character = touched.Parent
	if character and Players:GetPlayerFromCharacter(character) then
		character.Humanoid:MoveTo(Vector3.new(52.204, 3.882, 14.037))
		wait()
		script.Disabled = true
	end
end)
1 Like

Well, you will need to use BasePart/Touched

Here a sample exemple (i don’t try it)

script.Parent.Touched:Connect(function(hit)
		hit.Character.Humanoid:MoveTo(Vector3.new(52.204, 3.882, 14.037))
		wait()
		script.Disabled = true
end)

Put the script in the part because it’s “script.parent”

Keep in mind If you don’t want to define a variable for your part, you should iterate through workspace using a for loop and check if a property matches your desire, and connect a touched event to it.

1 Like