How can I set a certain range of values for my script?
Basically I want a property to change if the velocity of another brick hitting it is greater than 30, but lower than 90. I try this and even if it the part travels at 100 speed, it still gets its property changed.
local B1 = script.Parent.Parent.Parent.Car.B1 local HitBox = script.Parent HitBox.Touched:Connect(function(Part) if Part.Name == "B1" and Part.Velocity.Magnitude >= 30 and Part.Velocity.Magnitude <= 90 then print("It is B1!") script.Parent.Parent.B2.Transparency = 0 script.Parent.Parent.B2.CanCollide = true script.Parent.Parent.B1.Transparency = 1 script.Parent.Parent.B1.CanCollide = false else if Part.Name == "B1" and Part.Velocity.Magnitude >= 90 then print("It is B1!") script.Parent.Parent.B1.Transparency = 1 script.Parent.Parent.B1.CanCollide = false print("It isn't B1, it is ".. Part.Name .."!") end end end)
Hello, TheBeaver101!
You can use this script, on wat you want, you don't need to use .Magnitude
! you can simply test if the value is lower then the number you want
local B1 = script.Parent.Parent.Parent.Car.B1 -- This don't need to be defined, you don't use B1 on this script local HitBox = script.Parent HitBox.Touched:Connect(function(Part) if Part.Name == "B1" then if (Part.Velocity.y > 30 or Part.Velocity.x > 30 or Part.Velocity.z > 30) and (Part.Velocity.y < 90 or Part.Velocity.x < 90 or Part.Velocity.z < 90) then print("It is B1!") script.Parent.Parent.B2.Transparency = 0 script.Parent.Parent.B2.CanCollide = true script.Parent.Parent.B1.Transparency = 1 script.Parent.Parent.B1.CanCollide = false elseif (Part.Velocity.y >= 90 or Part.Velocity.x >= 90 or Part.Velocity.z >= 90) then print("It is B1!") script.Parent.Parent.B1.Transparency = 1 script.Parent.Parent.B1.CanCollide = false else print("Speed is lower than 30!") end else print("It isn't B1, it is ".. Part.Name .."!") end end)
Hope this helps!
Good Luck with your games!