Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Model Follow Mouse? How would I set a primary part cframe to a mode?

I want a model to have a position. I tried to set a primary part cframe but it kept telling me it was wrong.

Cursor.Move:Connect(function()
    local CursorPosition = Cursor.Hit.p
	local TurretPosition = Turret:SetPrimaryPartCFrame()
    local LookVector = Vector3.new(CursorPosition.X,TurretPosition.Y,CursorPosition.Z)
    TurretPosition.CFrame = CFrame.new(Gun.Position, LookVector)
end)

1 answer

✓ Accepted answer

:SetPrimaryPartCFrame() is a method of Instance that expects a modification argument so it can perform the adjustment accordingly. You're essentially calling a function within a variable that has a void return, no only that but it is is missing it's argument; TurretPosition becomes nil. You need to call this function on the Instance when you're ready to modify the CFrame property.

Cursor.Move:Connect(function()
    local CursorPosition = Cursor.Hit.p
    local TurretPosition = Turret:GetPrimaryPartCFrame().p
    local LookVector = Vector3.new(CursorPosition.X,TurretPosition.Y,CursorPosition.Z)
    Turret:SetPrimaryPartCFrame(CFrame.new(TurretPosition, LookVector))
end)

15 comments

0

ok

0

my brain in now scrambled from that but ok thank you

0

In the local turretPosition = turret.Position it wont work shouldnt it be cframe?

0

It has to be a Vector3, can you tell me why it’s not working?

0

this pops up 15:18:58.678 - Position is not a valid member of Model

0

Ah, easy fix, let me know if that worked!

0

ok

0

now this pops up 15:59:24.962 - Model:GetPrimaryCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.

0

Click on the Model Object and look in properties, is there a PrimaryPart Object set? If not, then click the empty box and click the centre most Instance of the model

0

would i have put the part name inside of Turret:GetPrimaryCFrame()? Like Turret:GetPrimaryCFrame(Body)?

0

That did it

0

thank you so much!

0

IVE BEEN WORKING ON THIS FOR WEEKS AND YOU DID IT! Thank you so much!!!!

0

You’re welcome!^•^

0

Dyk how to make the turret shoot where the mouse is?

This discussion is preserved as it was. New answers, comments, and votes are closed.