Trying to teleport a model in front of a player not working

Whenever I run the script show below I get an error message saying Unable to cast Vector3 to CoordinateFrame, but I saw a post using this system and no one said anything was done wrong in the solution post, and I can’t find the issue.

local deployed = 1
original = game.Workspace.Original

function leftClick()
	if deployed == 1 then
		local copy = original:Clone()
		copy.Parent = game.Workspace
		copy.Name = ("Copy-" .. tostring(game.Players.LocalPlayer.UserId))
		local characterCFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
		copy:SetPrimaryPartCFrame(characterCFrame*characterCFrame.LookVector*10)
		deployed -= 1
		print(deployed)
	else
		(game.Workspace["Copy-" .. tostring(game.Players.LocalPlayer.UserId)]):Remove()
		deployed += 1
		print(deployed)
	end
end

script.Parent.MouseButton1Click:Connect(leftClick)

When I print some of it out, if I change the characterCFrame to a Vector3 it becomes 0, 0, 0.


I don’t know how correct the CFrame the equation gives is, but Im gonna assume it’s correct because it looks about right. Because of this, I don’t think the equation is the problem.

2 Likes

The error is more than likely occurring here, supposedly your equation resulted as a Vector3 value

Try this perhaps?

		copy:SetPrimaryPartCFrame(CFrame.new(characterCFrame + characterCFrame.LookVector * 10))
3 Likes

Sadly, it didn’t work, at first I got an error that it expected a Vector3 not a CFrame, so I changed it to a Vector3 and it gave me the same error.

1 Like

Ill add this to the original post

1 Like

Reee ok, try this?

		copy:SetPrimaryPartCFrame(CFrame.new(Vector3.new(characterCFrame + characterCFrame.LookVector * 10)))

1 Like

it didn’t work again, I dont know if theres an alternative way to do this but im looking for one since it wont work.

1 Like

Are you sure that copy is a Model? And you’re defining the Player correctly? Try this just for confirmation:

local deployed = 1
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local RootPart = Character:WaitForChild("HumanoidRootPart")
original = game.Workspace.Original

function leftClick()
	if deployed == 1 then
		local copy = original:Clone()
		copy.Parent = game.Workspace
		copy.Name = ("Copy-" .. tostring(game.Players.LocalPlayer.UserId))
		local characterCFrame = RootPart.CFrame
		copy:SetPrimaryPartCFrame(characterCFrame*characterCFrame.LookVector*10)
		deployed -= 1
		print(deployed)
	else
		(game.Workspace["Copy-" .. tostring(game.Players.LocalPlayer.UserId)]):Remove()
		deployed += 1
		print(deployed)
	end
end

script.Parent.MouseButton1Click:Connect(leftClick)

Yes, copy is a model, you can look in the explore tab when you deploy and another one is created, just not brought to the player. And player seems to be fine too, because its giving me the same error, but I’ll keep that script if I can because it’s cleaner and does the same thing. I’m still getting the same error though.

Could you try again? I edited the script a bit, & if you need to add more print statements if you can

Okay, that fixed an error we were having, but we’re back to the original “Unable to cast Vector3 to CoordinateFrame” error.

Inhale

Change this line to this then perhaps :thinking:

copy:SetPrimaryPartCFrame(CFrame.new(RootPart.Position + characterCFrame.LookVector * 10))
1 Like

youll never believe this, it actually worked.
But, side note, you have to set the primary part first!

1 Like

image

OH MAH GOSH

Well you should’ve gotten an error though if you didn’t set a Primary Part for the Model?

1 Like

I did get an error for the primary part not being set, but then i set the primary part and it worked.
also i wanted to see if you could flag more than one as the answer, obviously, you cant.

1 Like

Oof, yeah just be sure to keep this in mind before attempting to move models :sweat_smile:

yeah good thinking, nice to have