Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I set a certain range of values for my script, because I want a property to change?

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)

1 answer

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!

4 comments

0

Thank you accept I want the second part to be only if the speed is greater than 90, so the first part between 30 and 90, and the second part after "else" to be higher than 90

0

But I don't want it to activate if it is under 30 speed. Right now if it gets hit even at 1 speed it changes which is weird.

0

script edited, try now

0

Now it doesn't work at all, this is really weird. Idk why roblox does this

This discussion is preserved as it was. New answers, comments, and votes are closed.