Hello, I’m currently scripting a cannon. The player uses the cannon by clicking on a part, then getting welded to another part and a LocalScript is given to them with control interface. The whole mechanisms of the cannon are based off of Welds, HingeConstraints and Attachments.
I get some strange behavior sometimes whenever I attempt using the cannon. Video below.
In the first half, the cannon moves according to the direction that the humanoid is facing. Usually, the cannon would be turned with WASD but here using WASD doesn’t even work; the player controls the turning. After the player would “leave” the cannon he’d get flung.
In the second half, the cannon moves normally. WASD to move, doesn’t move according to the humanoid. https://gyazo.com/cd9b24d05c6efd28f23ff463314c45d1
I have practically zero idea of what the heck is going on here, if you need more code or details by all means please LMK and I’ll provide it for you. If someone could figure out what’s going on that would be great!
Supposedly, I have controls to rotate the cannon. The LocalScript fires remote events to a Script inside the cannon, and that script changes hingeconstraint velocities. I don’t know if the player is supposedly pushing it or not, unless they have player control over the cannon? No clue
SERVER-SIDE SCRIPT MODULE
function CannonHandler.ChangeAimRequested(player, Cannon, AimDirection)
local Occupant = Cannon.Values.Occupant
local CannonRootHinge = Cannon.Chassis.CannonRoot.RootHinge
local ElevationRootHinge = Cannon.ElevatedParts.ElevationRoot.ElevationHinge
local WheelAxle = Cannon.Chassis.WheelAxle
local LeftWheelHinge = WheelAxle.LeftWheelHinge
local RightWheelHinge = WheelAxle.RightWheelHinge
local ShaftSlider = Cannon.Chassis.ElevationShaft.CannonSlider
if player == Occupant.Value then
if AimDirection == "Left" then
CannonRootHinge.AngularVelocity = 0.4
LeftWheelHinge.AngularVelocity = -0.8
RightWheelHinge.AngularVelocity = 0.8
end
if AimDirection == "Right" then
CannonRootHinge.AngularVelocity = -0.4
LeftWheelHinge.AngularVelocity = 0.8
RightWheelHinge.AngularVelocity = -0.8
end
if AimDirection == "Up" then
ElevationRootHinge.AngularVelocity = 0.1
ShaftSlider.AngularVelocity = 3
end
if AimDirection == "Down" then
ElevationRootHinge.AngularVelocity = -0.1
ShaftSlider.AngularVelocity = -3
end
if AimDirection == "StopRotation" then
CannonRootHinge.AngularVelocity = 0
LeftWheelHinge.AngularVelocity = 0
RightWheelHinge.AngularVelocity = 0
end
if AimDirection == "StopElevation" then
ElevationRootHinge.AngularVelocity = 0
ShaftSlider.AngularVelocity = 0
end
end
return
end
function CannonHandler.SeatLeave(player, Cannon)
local SitPart = Cannon.Chassis.SitPart
local Weld = SitPart:FindFirstChild("PlayerWeld")
if not Weld then return end
Weld:Destroy()
--collisions
wait(2)
Cannon.Chassis.CannonRoot.Anchored = false
Cannon.Chassis.RearChassis.CanCollide = true
Cannon.Chassis.CentralChassis.CanCollide = true
Cannon.Wheels.LeftWheel.CanCollide = true
Cannon.Wheels.RightWheel.CanCollide = true
--literally everything else
Cannon.Values.Occupant.Value = nil
if not Cannon.Chassis.CannonRoot.Anchored then
SitPart:SetNetworkOwnershipAuto()
end
Cannon.Chassis.WheelAxle.LeftWheelHinge.ActuatorType = Enum.ActuatorType.None
Cannon.Chassis.WheelAxle.RightWheelHinge.ActuatorType = Enum.ActuatorType.None
end
The problem was that the weld incorporated the SitPart and the HumanoidRootPart as its Part0 and Part1; apparently when I changed the HumRootPart to Torso it fixed.