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

Why is script executing code despite conditions?

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.

2 comments

0

What is the gp parameter supposed to be equal to?

0

gp is game processed. If the input is being processed by the game (like chatting)

1 answer

✓ Accepted answer

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)

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