Just a quick one, I'm trying to make a model follow the mouse or go to the mouse' location. I've stuck it in a while look just while I'm testing it but all I'm getting is this error;
20:30:08.985 - Workspace.Rock.Rock.Script:7: attempt to call method 'SetPrimaryPartCFrame' (a nil value)
The script below is literally only for testing purposes it's not the final product, but I can't quite work out what is wrong.
while true do wait() player = game.Players:FindFirstChild("Player1") mouse = player:GetMouse() parts = script.Parent:GetChildren() parts.PrimaryPart = parts.Rock parts:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.p.X,mouse.Hit.p.Y,mouse.Hit.p.Z)* CFrame.Angles(0, 0, 0)) end
You're not setting a PrimaryPart
On line 5
, you set parts
as GetChildren()
on the script's parent. This means parts
represents a table containing all those children - it doesn't represent a single object you can change that will edit everything upon changing it.
On line 6
, all you're doing is creating a PrimaryPart variable
within the GetChildren
table. This isn't effecting any of the objects. Same goes for calling SetPrimaryPartCFrame
- you're trying to call this from the GetChildren
table, not a part.
Solution
You don't need GetChildren
at all. Find a model, set it's PrimaryPart
property to a part, and then use SetPrimaryPartCFrame
on that model. Then you should be good to go.