When I try to teleport a part to my player, my player teleports to it instead

Im making a prop hunt game and would like to teleport a model to the player and morph.

However whenever I try to teleport the root part of the model to the player the player just teleports to the model instead

Here is my code:

local prop = ReplicatedStorage:WaitForChild("HideableStructures"):WaitForChild("Minertown"):WaitForChild("WoodPallet")
local worldprop = game.Workspace.WoodPallet
local ProximityPrompt =  worldprop.HumanoidRootPart:WaitForChild("ProximityPrompt")

local touch = game.Workspace.test
local db = true 

ProximityPrompt.ObjectText = "Wooden Pallet"
for _, part in ipairs(prop:GetChildren()) do -- weld the primary part of the model to all parts
	if part:IsA("BasePart") and part ~= prop.HumanoidRootPart then
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = prop.HumanoidRootPart
		weld.Part1 = part
		weld.Parent = part
		part.Anchored = false
	end
end

prop.HumanoidRootPart.Anchored = false

ProximityPrompt.Triggered:Connect(function(player) 
	if player and db == true then
		db = false
		print(player)
		local Disguise = prop:Clone()
		Disguise.Name = player.Name
		player.Character = Disguise
		
		local DisguiseRP = Disguise:FindFirstChild("HumanoidRootPart")
		local PlayerRP = player.Character:FindFirstChild("HumanoidRootPart")
		local PropPrimary = prop.PrimaryPart
		
		if DisguiseRP and PlayerRP then
			print(PlayerRP.CFrame) -- For some reason, prints the exact same number as the DisguiseRP one
			print(DisguiseRP.CFrame)
			DisguiseRP.CFrame = PlayerRP.CFrame
		end
		
		Disguise.Parent = workspace
		DisguiseRP.Anchored = false
		task.wait(1)
		db = true
	else
		print("i hate it all")
		print(player)
	end
end)


1 Like

You are first cloning the disguise, then setting the players character to that disguise and then checking position of the disguise and players character, which at that point are the same thing. You should first teleport the disguise to the player and then set players character to it.

1 Like

so i made some changes to the code here

local prop = ReplicatedStorage:WaitForChild("HideableStructures"):WaitForChild("Minertown"):WaitForChild("WoodPallet")
local worldprop = game.Workspace.WoodPallet
local ProximityPrompt =  worldprop.HumanoidRootPart:WaitForChild("ProximityPrompt")

local touch = game.Workspace.test
local db = true 

ProximityPrompt.ObjectText = "Wooden Pallet"
for _, part in ipairs(prop:GetChildren()) do -- weld the primary part of the model to all parts
	if part:IsA("BasePart") and part ~= prop.HumanoidRootPart then
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = prop.HumanoidRootPart
		weld.Part1 = part
		weld.Parent = part
		part.Anchored = false
	end
end

prop.HumanoidRootPart.Anchored = false

ProximityPrompt.Triggered:Connect(function(player) 
	if player and db == true then
		db = false
		print(player)
		local Disguise = prop:Clone()
		Disguise.Name = player.Name
		
		local DisguiseRP = Disguise:FindFirstChild("HumanoidRootPart")
		local PlayerRP = player.Character:FindFirstChild("HumanoidRootPart")
		local PropPrimary = prop.PrimaryPart
		Disguise.Parent = workspace

		if DisguiseRP and PlayerRP then
			print(PlayerRP.CFrame) -- For some reason, prints the exact same number as the DisguiseRP one
			print(DisguiseRP.CFrame)
			DisguiseRP.CFrame = PlayerRP.CFrame
		end
		
		player.Character = Disguise

		DisguiseRP.Anchored = false
		task.wait(1)
		db = true
	else
		print("i hate it all")
		print(player)
	end
end)


now the player stays in place and the prop teleports, but the players camera doesnt follow the prop for some reason

I believe you need to set the camera subject to the prop after setting the player’s character to it. You can do it with a local script which sets the camera subject when player’s character loads:

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local function characterAdded(char)
	camera.CameraSubject = char
end

if player.Character then
	characterAdded(player.Character)
end
player.CharacterAdded:Connect(characterAdded)

not working for some reason, i tried adding print to the local function and it didnt print anything.

i probably have to set the camera subject to primary part

wait nah its still not printing anything even when i put the print at top of local script i dont think local is working

Are you sure the local script is located in a right place? You should put it in StarterGui or StarterPlayerScripts.

1 Like

ok its working now. a new issue though is that my shift lock isnt working

Is it not working at all, or just when you turn into a prop? I’ve tried recreating this with a prop model that has a Humanoid and a prop itself named HumanoidRootPart and everything works as expected.

wait i fixed it by setting camera subject to humanoid thanks anyways though