I want to achieve a working false to true switch, the problem is that it is not working at all or that the script where the switch is needed, is not working.
Server script part:
if KEY == "Flying[E]" then
if SkillsFolder.Flying.Value == false then
SkillsFolder.Flying.Value = true
elseif SkillsFolder.Flying.Value == true then
SkillsFolder.Flying.Value = false
end
local FlyingAnimations = {
FlyingIdle = Humanoid:LoadAnimation(game.ServerStorage.Animations.FlyingIdle)
}
repeat
FlyingAnimations.FlyingIdle:Play()
FlyingAnimations.FlyingIdle.Stopped:Wait()
until SkillsFolder.Flying.Value == false
end
Apparently it is, it doesn’t set the boolean to false.
So i removed the switch out of the server script, and put inside the localscript where it fires the RemoteEvent for the flying skill:
elseif InputKey.KeyCode == Enum.KeyCode.E then
local CurrentBoolean = false
if not CurrentBoolean then
CurrentBoolean = true
elseif CurrentBoolean then
CurrentBoolean = false
end
SkillEvent:FireServer("Flying[E]","",CurrentBoolean)
while wait() do
warn(CurrentBoolean)
end
end
I’m having this issue too, oddly, with the following:
-- Other stuff up here ofc
isNeonOn = not isNeonOn
for _, neonData in pairs(neonParts) do
if isNeonOn then
neonData.part.Color = neonData.originalColor -- Turn on (restore original color)
else
neonData.part.Color = Color3.new(0, 0, 0) -- Turn off (set to black)
end
end
You’re redefining the value of CurrentBoolean every time the player presses E; the initial value is always false. You need to define the variable outside of this block of code to avoid resetting its value every time.
For example,
local someBool = false
while true do
someBool = not someBool
print(someBool)
task.wait(1)
end
true
false
true
false
…
But what you have is effectively this
while true do
local someBool = false -- Being defined inside resets the value every time
someBool = not someBool
print(someBool)
task.wait(1)
end
The logic in this code looks fine, your problem is elsewhere. One stylistic nitpick is you could simplify it with an inline if:
isNeonOn = not isNeonOn
for _, neonData in neonParts do
-- Original color if on, black if off
neonData.part.Color = if isNeonOn then neonData.originalColor else Color3.new(0, 0, 0)
end
Someone else posted recently here first, so it showed up at the top of the feed for me and I didn’t see the original post was old. But apparently it was unresolved anyway lol