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?

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)

2 comments

0

Well your elseif statement specifically allows velocity over 90. I'm not gonna answer since you didn't explain that.

0

Maybe I would've explained it if I realized. Don't jump to conclusions buddy.

1 answer

Does this solve your problem? [EDITED]

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
		script.Parent.Parent.B2.Transparency = 0
		script.Parent.Parent.B2.CanCollide = true

		script.Parent.Parent.B1.Transparency = 1
		script.Parent.Parent.B1.CanCollide = false
	end
end)

5 comments

0

No it's not really working right. I just want the original script to work when the velocity is over 30 and below 90.

0

Ok, but what exactly do you want to happen if velocity is over 30 and below 90?

0

The properties to change of B2 and B1.

0

I've edited the answer above. It would make it so that if a part called "B1" hits the hitbox, and its velocity is between 30 and 90, then B2 will be visible and B1 will be invisible.

0

Thank you but I already tried that and it didn't work. I can't seem to figure it out. I think i can make the script more simple.

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