Does an if statement work like an event? Heres kind of an example:
WHEN the brick turns yellow, it runs code.
Can that happen with just an if statement with no code inside the brick?
Does an if statement work like an event? Heres kind of an example:
WHEN the brick turns yellow, it runs code.
Can that happen with just an if statement with no code inside the brick?
No. You cannot use if statements to completely replace events.
You can use them in conjunction with events to produce different results based on what was changed.
workspace.Part:GetPropertyChangedSignal("BrickColor"):Connect(function()
if workspace.Part.BrickColor == BrickColor.new("New Yeller") then
-- i have turned yellow!!
end
end)
an if statement can't replicate the behavior of an event, they just check a condition at the specific point in time the code was ran
-- assuming this is your entire script...
if brick.Color == Color3.new(1, 1, 0) then -- ...this would only check the color of a brick when the script first starts running
end
there's almost no way to replicate the behavior of events without using some form of busy waiting or polling, or making your scripts ridiculously overcomplicated
I mean, at the first look it does look kind of impossible but here is my "guess"
It may be right. Because You can put a script in ServerScriptService and then write
local part = game.Workspace.Part
if part.BrickColor == BrickColor.new("Pastel Yellow") then
part.Name = "YellowPart"
end
So, I GUESS You are maybe right.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
But That Does not mean You should ditch events and start using if statements, Because there is no if statement that can prove that a part is touched without uselessly being complicated using magnitude or stuff like that. People use if statements in EVents to use the parameters and stuff like that. so You are JUST a little right but that does not mean You should ditch events. They are really easy