Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
2
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

: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)
0
ok Nervousmrmonkey2 118 — 4y
0
my brain in now scrambled from that but ok thank you Nervousmrmonkey2 118 — 4y
0
In the local turretPosition = turret.Position it wont work shouldnt it be cframe? Nervousmrmonkey2 118 — 4y
0
It has to be a Vector3, can you tell me why it’s not working? Ziffixture 6913 — 4y
View all comments (11 more)
0
this pops up 15:18:58.678 - Position is not a valid member of Model Nervousmrmonkey2 118 — 4y
0
Ah, easy fix, let me know if that worked! Ziffixture 6913 — 4y
0
ok Nervousmrmonkey2 118 — 4y
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. Nervousmrmonkey2 118 — 4y
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 Ziffixture 6913 — 4y
0
would i have put the part name inside of Turret:GetPrimaryCFrame()? Like Turret:GetPrimaryCFrame(Body)? Nervousmrmonkey2 118 — 4y
0
That did it Nervousmrmonkey2 118 — 4y
0
thank you so much! Nervousmrmonkey2 118 — 4y
0
IVE BEEN WORKING ON THIS FOR WEEKS AND YOU DID IT! Thank you so much!!!! Nervousmrmonkey2 118 — 4y
0
You’re welcome!^•^ Ziffixture 6913 — 4y
0
Dyk how to make the turret shoot where the mouse is? Nervousmrmonkey2 118 — 4y
Ad

Answer this question