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

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

Asked by 5 years ago
Edited 5 years ago

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!

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? 1waffle1 2908 — 5y
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 kizi3000 88 — 5y
0
What class is valueObj, and what is line 16 actually printing? 1waffle1 2908 — 5y
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. SerpentineKing 3885 — 5y
View all comments (3 more)
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 kizi3000 88 — 5y
0
1waffle1 your first comment fixed it, I just changed the number 60 to "60" and it worked kizi3000 88 — 5y
0
also I changed 10 to "10" kizi3000 88 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

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 kizi3000 88 — 5y
Ad

Answer this question