Stumped creating a script to change a number value on multiple instances

I’m trying to recreate the cart ride system. To make the cart move forward or backward, each individual wheel spins by using AngularVelocity, a number value, from a HingeConstraint Motor.

Since I have multiple AngularVelocity values to update, how do I update all of them at once without having to write code for each individual HingeConstraint? Any amount of help will do.

2 Likes

a ‘for loop’ like this, maybe?

local wheels = game.Workspace.CART.Wheels -- put your path to the wheels folder here

for i,v in pairs(wheels:GetChildren()) do -- v is whatever it finds as a child of wheels, so it finds the parts the hinge constraints are under
	if v:FindFirstChild("HingeConstraint") then 
		v:FindFirstChild("HingeConstraint").AngularVelocity = -6 -- or, whatever number you may want it to be
	end
end

Even if my example doesn’t fit your use case/solve your issue, I very much do recommend looking at for loops in general, because I’m certain they’re the solution to your problem. I wish you the best of luck!

2 Likes

It worked!

tbh, I’m pretty new to FindFirstChild and WaitForChild, and having examples like these really help me out. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.