How do i change a humanoids position when touching part?


local End = workspace.End

End.Touched:Connect(function(ontouch)
	local humanoid = ontouch.Parent:FindFirstChild("Humanoid")
	if humanoid  then
		Wins.Value = Wins.Value +1
		humanoid.Position = Vector3.new(8.1, 2.5, 0.2)
	end
end)

end)

2 Likes

change the CFrame of the characters HumanoidRootPart

ontouch.Parent.HumanoidRootPart.CFrame = CFrame.new(8.1, 2.5, 0.2)

setprimarypartcframe to move the entire character

There are a few issues with this:

  1. The CFrame.new args need to be a Vector3
CFrame.new(Vector3.new(8.1, 2.5, 0.2)
  1. You are moving just the HumanoidRootPart, which will cause the character to break. You need to Pivot the player’s character model instead

SetPrimaryPartCFrame is now deprecated, it has been replaced with PivotTo()

Putting these two corrections into practice, you can properly change the characters position by doing:

End.Touched:Connect(function(ontouch)
	local humanoid = ontouch.Parent:FindFirstChild("Humanoid")
	if ontouch and humanoid  then
		Wins.Value = Wins.Value +1
		ontouch.Parent:PivotTo(CFrame.new(Vector3.new(8.1,2.5,0.2))
	end
end)

You should more likely check if game.Players:GetPlayerFromCharacter(ontouch.Parent) == joined or if the instance who touched it has a player to make the Touched Event work better, since ontouch can be an accessory.

But to answer the question, you need the HumanoidRootPart, not the humanoid

1 Like

theres another error

Just add an ) at the end of this line

ontouch.Parent:PivotTo(CFrame.new(Vector3.new(8.1,2.5,0.2)))

Apologies for that error

Thanks for your help, much appreciated

1 Like

false
RobloxStudioBeta_7dekDSUHCu

false
RobloxStudioBeta_nssxlJ0lF3

Technically, it does still need a Vector3, but if you don’t use a Vector3 format it will automatically convert it. That is just the way I learned to use CFrame.new

As for the HumanoidRootPart, it makes sense as all of the parts are welded by Motor6d’s (Essentially a weld that allows for animation). I gained the habit of just pivoting the model because not every model is welded.