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

[INFO] Can I use events as if statements?

Hi! So, around 2 hours ago, I made a question asking if I can use events as if statements. Well I wasn't very informative about what I meant so I remade this question again but with more information regarding my question.

So, I have a game that has stages and my remote functions cannot really catch the stage that the player is in changing. And since Stage is a value of Leaderstats. I know i can use an event named Changed. But I already kind of have a remote function that I do not want to ruin. I only want the event activating when necessary. And not stopping the entire script until it activates.

So, Do I use Changed:Wait? Like this?

local stage = player.leaderstats.Stage.Value

remoteFunction.OnServerInvoke = function()
if stage.Changed:Wait() then
-- do code
else
-- do code
	end
end

Or do I use it as an If statement? Like this:

local stage = player.leaderstats.Stage.Value

remoteFunction.OnServerInvoke = function()
if stage.Changed then
--do code
else
-- do code

1 comment

0

In the second script i think its valid

2 answers

✓ Accepted answer

Long story short, yes. Events return true if they were executed correctly, your code won't run if the function returned false/nil.

No, i dont believe so if i was going to do what you did in first i would do:

local stage = player.leaderstats.Stage.Value
local changed = false

stage.Changed:Connect(function()
	if changed == false then
 
	changed = true 

else

	end
end)

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