In attempt to make some changes to the Roblox physics, I’ve run into a strange issue. I want to make it so that part velocities get randomized upon having their velocities changed, but for some reason it isn’t working correctly.
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function()
if v:GetPropertyChangedSignal("Velocity") and v.Anchored == false then
v.Velocity = Vector3.new(math.random(-200,200),math.random(0,200),math.random(-200,200))
print("change")
wait(2)
end
end)
end
end
What ends up happening is every single part having its velocity randomized, causing every single unanchored part to go flying and players on the baseplate to be flung. I only want parts that have their velocity changed randomized.
When you change the velocity, it invokes GetPropertyChangedSignal which changes velocity and that loops.
You will have to add a debounce to that part somehow, I suggest adding an BoolValue under the part and removing it after a certain amoint of time. You can use FindFirstChild to check the debounce.
You’re incorrectly using :GetPropertyChangedSignal() it is an RbxScriptSignal.
for _, child in pairs(workspace:GetDescendants()) do
if (child:IsA('BasePart')) then
child:GetPropertyChangedSignal('Velocity'):Connect(function()
-- do your code
end)
end
end
I tried doing this, but nothing appears to happen. I tried making the script print “change” upon changing the velocity but nothing seems to happen whenever I run it.
for _, child in pairs(workspace:GetDescendants()) do
if (child:IsA('BasePart')) then
child:GetPropertyChangedSignal('Velocity'):Connect(function()
child.AssemblyLinearVelocity = Vector3.new(child.AssemblyLinearVelocity * 200000, math.random(500,2000), child.AssemblyLinearVelocity * 200000)
print("change")
end)
end
end
iirc properties fired by roblox physics doesnt fire the .Changed or GetPropertyChangedSignal
and u also used it wrongly but eitherway it wont fire anyways