Hello, I’m trying to make it so that when you Turn off a light generator various things happen, I’m not using a single script though, so I needed a way to make them communicate somehow, because of this I used a module script for simplicity and a bool value to make something specific happen - if that makes sense.
Basically, everything works just fine, the module script changes the value as intended and all the other things that should be happening happen
Like shown here
The thing is that when I try to check if that bool value is true or false in another script, it just doesn’t work.
Here’s the first part of the script.
Juggling = true
local hum = script.Parent:WaitForChild("Humanoid")
local a = hum:LoadAnimation(script.Idle)
local b = hum:LoadAnimation(script.Restless1)
local c = hum:LoadAnimation(script.Restless2)
local d = hum:LoadAnimation(script.Restless3)
local e = hum:LoadAnimation(script.Juggling1)
local GenValue = script.GeneratorOn
if GenValue.Value == false then
print("Gen Value Changed")
end
if Juggling == true then
e:Play()
end
The “Juggling” animation works so I guess it just skips the print statement?
I’m as new as you can be to scripting so I might be doing something wrong here, I just don’t know what.
The bool value is inside the script above.
What I wanted to do though is that once the bool value becomes false then Juggling = false and when the bool value becomes true again then Juggling = true
but if I make it:
while task.wait(0.75) do
if GenValue.Value == false then
Juggling = false
end
end
The juggling animation stops as soon as I start the game even though the value is set to True as default
Okay, so loops are plainly inefficient, and there’s no point in doing them, as there are several other methods. GetPropertyChangedSignal (Instance | Roblox Creator Documentation) does not produce lag, and it’s a simple event/function (kind of. It monitors a simple property of an instance and when it’s changed it fires an event.). Also @AridFights1 said that Humanoid:LoadAnimation() is deprecated, which is true, Animator is the child of Humanoid, which is a very simple change. So just change everything like Arid Said above.
The “NewValue” is the value that is in the BoolValue, like, if you change the BoolValue to “true”, then this event will return to you the new value that is “true” now
Thanks, it now detects when a change happens to the value
Unfortunately, it doesn’t change the animation, which is a separate problem I guess, but I’m not sure why.
Juggling = true
local hum = script.Parent:WaitForChild("Humanoid")
local a = hum:WaitForChild("Animator"):LoadAnimation(script.Idle)
local b = hum:WaitForChild("Animator"):LoadAnimation(script.Restless1)
local c = hum:WaitForChild("Animator"):LoadAnimation(script.Restless2)
local d = hum:WaitForChild("Animator"):LoadAnimation(script.Restless3)
local e = hum:WaitForChild("Animator"):LoadAnimation(script.Juggling1)
local GenValue = script.GeneratorOn
GenValue.Changed:Connect(function(NewValue)
if NewValue then
Juggling = true
print("Juggling is true")
else
Juggling = false
print("Juggling is false")
end
end)
if Juggling == true then
e:Play()
end
while Juggling == false do
local creepyIdle = true
while creepyIdle==true do
a:Play()
wait(1.5)
local x = math.random(1,3)
if x==3 then
creepyIdle = false
end
end
local z = math.random(1,3)
if z==1 then
b:Play()
elseif z==2 then
c:Play()
elseif z==3 then
d:Play()
end
wait(0.2)
end
Oh nvm I forgot juggling was a loop animation, but shouldn’t starting a new animation override the current one? Edit: If I stop the juggling animation on “Juggling == false” the other one doesn’t play anyway, and now the teddy is just T-Posing xP
In the while loop, it will only run the code while the Juggling is false, once it’s true, the loop will stop and won’t run again later, what you can do is to manage the animations when the value is changed. You can do too another function to manage the animations, like:
local function AnimationHandler()
if Juggling == true then
-- Play one animation
else
-- Play another animation
end
end
GenValue.Changed:Connect(function(NewValue)
if NewValue then
Juggling = true
print("Juggling is true")
else
Juggling = false
print("Juggling is false")
end
AnimationHandler()
end)