AngularVelocity Not Changing

I have a LocalScript in StarterPlayerScripts that fires when certain parts are clicked. Here is the script:

local speed = game.Workspace.SpinStand.HingeConstraint.AngularVelocity
local slow = game.Workspace.SlowSpinSpeed
local med = game.Workspace.MedSpinSpeed

slow.ClickDetector.MouseClick:Connect(function()
    speed = 1.5
    print("Slower")
end)

med.ClickDetector.MouseClick:Connect(function()
    speed = 4
    print("Normal")
end)

For some reason, the AngularVelocity for the HingeConstraint doesn’t change when the parts are clicked. I tested it, and I checked and saw that it stayed the same. I know the script is running when it’s clicked because the
print() messages appear in the output.

  1. What do you want to achieve? I want to make it so when certain parts are clicked, the AngularVelocity of a HingeConstraint changes.

  2. What is the issue? The script fires correctly, except the AngularVelocity doesn’t change for some reason.

  3. What solutions have you tried so far? I searched for similar posts, and look at the Developer Hub, but I found nothing that could help me.

I don’t know if there’s something that I’m just not seeing or not. Any help is appreciated. :slightly_smiling_face:

1 Like

This line initializes the ‘speed’ variable and sets its value to the current AngularVelocity of the HingeConstraint.

This line assigns a new value to the ‘speed’ variable (1.5). It does not change the AngularVelocity property. To achieve the effect you want here, you need to directly change the AngularVelocity property:

- local speed = game.Workspace.SpinStand.HingeConstraint.AngularVelocity
+ local hinge = game.Workspace.SpinStand.HingeConstraint
local slow = game.Workspace.SlowSpinSpeed
local med = game.Workspace.MedSpinSpeed

slow.ClickDetector.MouseClick:Connect(function()
-   speed = 1.5
+   hinge.AngularVelocity = 1.5
    print("Slower")
end)

med.ClickDetector.MouseClick:Connect(function()
-   speed = 4
+   hinge.AngularVelocity = 4
    print("Normal")
end)

I have used diff syntax here to show you the changes I made. You’ll need to remove the red lines and the plus/minus symbols I have added for the highlighting.

6 Likes