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

Why does code ignore if statement and fire regardless?

Asked by
Romul 21
5 years ago

I've made a code that checks if a tool is in the Backpack or not. If it is in the backpack, the code is supposed to bypass the primary action and move on. Unfortunately, it runs the primary action regardless if the tool is in the Backpack or in the Player. I used a print code to test this, and sure enough, each time it runs, if the tool was in the Backpack it printed "Backpack" and if it was in the player it printed my name. Any ideas why? This is in a local script inside of a tool. Thanks in advance!

if player.Backpack.MyValue.Value == false then
    FanimTrack:Play()
    wait(.4)
    player.Character.Head.MySound:Play()
    wait(.6)
    if bin.Parent ~= "Backpack" then
        enabled = false
        print(bin.Parent.Name)
        player.Backpack.MyValue.Value = true
        --My FireServer Event
        wait(4)
        player.Backpack.MyValue.Value = false
        wait(4)
        enabled = true
    end
    FanimTrack:Stop()
end
0
If statements are not ignored, if its running then the conditions you've given it have been met. DinozCreates 1070 — 5y
0
Right, that is my understanding of it as well. In the code above though, it doesn't matter if the parent is the Player or the Backpack, it runs the command either way. Though I specify that it should run if it is not in the Backpack, it still does.. Romul 21 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You are trying to compare an object to a string. You wanted to compare it's Name to your string.

bin.Parent.Name ~= "Backpack"
1
You're absolutely right. I didn't even put two and two together. Thanks! The code is working 100% as expected now! I just hate/love it when it's something so simple.. Romul 21 — 5y
Ad

Answer this question