Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I set a certain range of values for my script?

Asked by 6 years ago

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)
0
Well your elseif statement specifically allows velocity over 90. I'm not gonna answer since you didn't explain that. cabbler 1942 — 6y
0
Maybe I would've explained it if I realized. Don't jump to conclusions buddy. TheBeaver101 28 — 6y

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

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)
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. TheBeaver101 28 — 6y
0
Ok, but what exactly do you want to happen if velocity is over 30 and below 90? UgOsMiLy 1074 — 6y
0
The properties to change of B2 and B1. TheBeaver101 28 — 6y
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. UgOsMiLy 1074 — 6y
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. TheBeaver101 28 — 6y
Ad

Answer this question