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

Script not checking if a value is below 30?

Asked by 5 years ago
Edited 5 years ago

In a script, I have a number value that constantly changes. However, when the value reaches below 30, the script does not make the changes shown

wait(2)
print("ready")
local bgm = script.Parent.chase
local val = script.Parent.distanceval.Value
bgm:Play()


while val < 30 do

    print("less30")
    bgm.Volume = .5
    wait(0.2)   

end

Instead of changing the volume and printing, it does nothing. Why does it do this and how can I fix it?

0
Are you sure it's never going over thirty at any point in time? Does the output print any errors? chasedig1 115 — 5y
0
No errors. It only checks when the game begins, so if I set the value to less than 30 before I test the game, the script works. However, anything after that does not work. flufffybuns 89 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Hey fluffybuns,

I do believe your issue is that your script isn't noticing that val is below 30!

I experimented around a bit and I think this might do what you want. I'm not sure if you want the sound to be turned up every value of val or just once. I made this so it gets played once.

Hopefully, it does what you want! If not, let me know I'll look more into it!

Deathmatch7540

wait(2)
print("ready")
local bgm = script.Parent.chase
local val = script.Parent.distanceval.Value
local x = false
bgm:Play()


while x == false do

    if val < 30 then --If you want the sound to turn up at 30 then you should just add "="

        print("less30")
        bgm.Volume = .5
        wait(.2)
        x = true

    end 

end
0
hmm, still doesnt seem to be working for some reason... flufffybuns 89 — 5y
0
Is it causing any errors? Or is the task not being executed? Also, what is executed deathmatch7540 7 — 5y
0
basically, what i'm trying to do is make a song gradually louder as you get closer to the specified object. in one of the scripts, it calculates the distance and puts the value into a 'NumberValue' object. However, when trying to check if the number is lower than 30, it doesn't work, despite no errors showing in the output. Is there another method of doing this rather than this? flufffybuns 89 — 5y
0
I don't wanna put the audio into a part in the workspace because that's not what im trying to do. flufffybuns 89 — 5y
View all comments (3 more)
0
I'll do some quick experimenting and see what can work! deathmatch7540 7 — 5y
0
Maybe try this in replace of the original bgm.Volume -- bgm.Volume = bgm.Volume + .05 deathmatch7540 7 — 5y
0
how would that work though? flufffybuns 89 — 5y
Ad

Answer this question