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

detects one print but doesn't detect the If statement print?

I'm making a sliding door that is supposed to print("test") if newVal == 60 but for some reason it doesn't, although it does print("ran", newVal) could someone please tell me why it doesn't detect if newVal == 60 ? Here is the script (It is a server script inside of a part which is located in workspace):

local valueObj = game:WaitForChild("ServerStorage").ElevatorValues.Easy.Intermission

valueObj.Changed:Connect(function(newVal) 
    if newVal == 60 then
	print("test")
        for i=1, 100 do
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0.1, 0)
            wait()
        end
    elseif newVal == 10 then
        for i=1, 100 do
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, -0.1, 0)
            wait()  
        end
    end
    print("ran", newVal)
end)

If you have any idea why this isn't working please help!

7 comments

1

You say it does print "ran", newVal. What number does it print when it prints that? Is it 60? If it is 60 then is it actually a StringValue, making the 60 a string and not a number?

0

I have a different script that makes the intermission value start at 65 then changes it by -1 each second but that works fine

0

What class is valueObj, and what is line 16 actually printing?

0

My question is what is newVal printing? Based on the code, if the newVal == 10 line is running (thus giving the read-out) then there must be something wrong with your newVal so that the number 60 is never expressed.

0

I have a script that changes the value to 65 then changes by -1 each second and the print("ran", newVal) prints ran 65 then ran 64, ran 63, ran 62, ran 61, ran 60, ran 59 and so on until it gets to 0 and stops

0

1waffle1 your first comment fixed it, I just changed the number 60 to "60" and it worked

0

also I changed 10 to "10"

1 answer

Make sure the "newVal" variable received by the function is an integer, if it is an object, it will not work, or if it is a string, it must be converted to an integer.

1 comment

0

1waffle1 already answered the problem in the first comment he posted (I had to change the number to a string because the variable was a string but had the value of a number

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