Cloning model to root part won't work for no reason

so i’m learning how to script again and doing the fireball thing again. it worked for literally every other tool but this one doesn’t want to clone correctly. it thinks it the ignored folder is the cframe when it’s supposed to be welded to the root. it displays as “Model?” when i type out character even though i defined it before

local

local rep = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()

local tool = script.Parent

tool.Activated:Connect(function()
	tool.Garbage:FireServer(mouse.Hit)
	print("fire")
end)

server

tool.Garbage.OnServerEvent:Connect(function(player,mouseHit)
	
	local character = player.Character
	
	local garbage = rep.TrashAttack.Trashbag:Clone()
	garbage.Parent = workspace.Ignore
	garbage.CFrame = character.HumanoidRootPart.CFrame

image
image

3 Likes

Models do not have a CFrame. They do, but not directly.

Models utilize a function called :PivotTo(). It functions the same as setting the CFrame, but it will move all the parts/instances inside of the model for you.


Example:

local garbage = rep.TrashAttack.Trashbag:Clone()
garbage.Parent = workspace.Ignore
garbage:PivotTo(character.HumanoidRootPart.CFrame)
4 Likes

Edit to that:
You could also just clone the MeshPart. And if you are using the :PivotTo() method, make sure that you have set a PrimaryPart for the Model.

1 Like

god that makes so much more sense, i wonder why it didn’t show in the docs for some reason

ALSO it worked but run service isbutchering my game HELP

local connection
connection = run.Heartbeat:Connect(function(dt)
	garbage.CFrame = CFrame.new(garbage.Position) * mouseHit.LookVector * dt * 60
end)

end)

it supposed to shoot out the mouse position, i have no clue why it’s parenting to the ignored folder (it’s for raycasting)

1 Like

Because in the cloning portion of the script, you parent it to the Ignore folder. Quote:


In the connection you are again setting the CFrame of the model, which it does not have.
Instead, translate the formula to accustom to the :PivotTo() function.

Before:

garbage.CFrame = CFrame.new(garbage.Position) * mouseHit.LookVector * dt * 60

After:

local garbagePivot = garbage:GetPivot() --//This obtains the model's current CFrame/Pivot

garbage:PivotTo(garbagePivot * mouseHit.LookVector * dt * 60)
1 Like

it’s parented to ignore since that’s supposed to be the universal folder for raycasts and clones

@Iemny


YOU NEARLY CRASHED MY GAME, i never have problems like these whenever i do these tutorials

	local garbagePivot = garbage:GetPivot()
	local connection
	connection = run.Heartbeat:Connect(function(dt)
		garbage:PivotTo(garbagePivot * mouseHit.LookVector * dt * 60)
	end)
end)

I suggest looking deeper into the error you’re getting. It says you’re trying to cast a Vector3 (Position) to something that only accepts a CoordinateFrame (CFrame).

In the function I provided, I only use CFrames, so the error resides somewhere else.

dude i have no idea, i follow the tutorial text for text and the script is having humanoid problems, like it doesn’t even auto fill. can you look through the script i sent again? it doesn’t even show where the error is

Then please provide the full ServerScript where the error comes from. It says the error happens in Line 17, and the only script you sent counts 7 lines total.

local rep = game:GetService("ReplicatedStorage")
local run = game:GetService("RunService")

local tool = script.Parent

tool.Garbage.OnServerEvent:Connect(function(player,mouseHit)
	
	local character = player.Character
	
	local garbage = rep.TrashAttack.Trashbag:Clone()
	garbage.Parent = workspace.Ignore
	garbage:PivotTo(character.HumanoidRootPart.CFrame)
	
	local garbagePivot = garbage:GetPivot()
	local connection
	connection = run.Heartbeat:Connect(function(dt)
		garbage:PivotTo(garbagePivot * mouseHit.LookVector * dt * 60)
	end)
end)

i’m upset i can’t figure this out

I think I have the issue.

mouseHit.LookVector returns a Vector3 or Position value.
Using the mouse’s mouse.Hit returns a CFrame value of where the mouse clicked.

I am guessing that your mouseHit paramater is the mouse.Hit property, so if I am right, change this line in the connection as follows:

...
		garbage:PivotTo(garbagePivot * mouseHit * dt * 60)
...

this also didn’t work, and lagged even harder. what should i do?