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

Why isn't the code working when the part is welded?

Asked by
Xyternal 247 Moderation Voter
3 years ago

So I was searching up some YouTube tutorial videos, and I wanted to make my boat move. Here is my code.

local Engine = game.Workspace.car.Model.Engine.BodyThrust --The Force making the boat move
local SForce = game.Workspace.car.Steer.BodyAngularVelocity -- The force making the boat turn
local DSeat = script.Parent -- The driver seat
local Base = game.Workspace.car.Model.Base -- The base part of the boat

speed = 5000 -- The force of 'Engine'
SteerSpeed = 25 -- The force of SForce
BaseDensity = .1 -- Lower this is your boat can't float, make it higher to make it go more in the water

DSeat.Changed:Connect(function(p)
    if p == "ThrottleFloat"then
        Engine.Force = Vector3.new(0,0,speed * DSeat.ThrottleFloat)
    end
    if p == "SteerFloat"then
        SForce.AngularVelocity = Vector3.new(0,-SteerSpeed*DSeat.SteerFloat,0)
    end
end)

Base.CustomPhysicalProperties = PhysicalProperties.new(BaseDensity,0,0)

So it works when I test it without welding the engine, but when i weld the engine, the boat doesn't move. One more question... I have a drivers seat, and do i need a script to make it move? Please answer my questions. Thanks!

2 answers

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Hey! I believe that you are trying to move an entire boat, but it looks like your welded part is anchored! That's why it wont move, you should make it as a model, and go to the model > properties > PrimaryPart, set it to the base part of the boat.

Now you should move it with :SetPrimaryPartCFrame, rotating it need to use math.Angles, just a note, every orientation you put should do math.rad. Heres a sample:

for i = 1, 100, 1 do
    game.Workspace.Model:SetPrimaryPartCFrame(0, i, 0) * math.Angles(math.rad(10), 0, math.rad(50))
end
0
Everything you put in the model will be moved when you put SetPrimaryPartCFrame, by the way, it's all entirely moved to a direction based on the PrimaryPart, so you should not use pairs loop because it squashes all the parts inside a setted direction which does not work Xapelize 2658 — 3y
0
The last thing: is primarypart important, it depends Xapelize 2658 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

Yeah I think you need to script It to move

0
Can you tell me whats wrong though. Xyternal 247 — 3y
0
wydm? imnotaguest1121 362 — 3y
0
Like whats wrong in the code. So I got my answer to my second question, now i want the answer to my first Xyternal 247 — 3y

Answer this question