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

Why is script executing code despite conditions?

Asked by
phim37 4
5 years ago

I've encountered an extremely odd issue with my code. For some reason, my code is being executed despite conditions I've put in. Below is some sample code that demonstrates my issue (Local script)

game:GetService("UserInputService").InputBegan:connect(function(input,gp)
    local f = true
    if f == true then
        f = false
        print("I can eat peanut butter")
    end
end)

Despite the conditions placed inside the if statement and the fact that variable f turns to false, the script still prints "I can eat peanut butter" no matter what. It is extremely odd. If anyone has any info about this or know how to deal with it, please comment.

0
What is the gp parameter supposed to be equal to? DominousSyndicate 41 — 5y
0
gp is game processed. If the input is being processed by the game (like chatting) User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

f should be at the top

local f = true
game:GetService("UserInputService").InputBegan:Connect(function() -- Your not using them, so I'll remove them.
    if f == true then
        f = false
        print("I can eat peanut butter")
    end
end)
Ad

Answer this question