I have a NumberValue in replicated storage that helps two scripts know when to do stuff, my scripts work but any if statement that has to do with the value or something wont work. Here are the two scripts:
local animation = script:WaitForChild('Animation') local animation2 = script:WaitForChild('Animation2') local humanoid = script.Parent:WaitForChild('Humanoid') local dance = humanoid:LoadAnimation(animation) local dance2 = humanoid:LoadAnimation(animation2) local MuscleOn = game.ReplicatedStorage.MuscleOn if MuscleOn == 1 then print("z") dance:Play() end if MuscleOn == 2 then dance2:Play() end
local button = script.Parent local text = button.Parent local MuscleValue = game.ReplicatedStorage.MuscleOn text.Text = "Its the hammer, hes real!" if text.Text == "Its the hammer, hes real!" then button.MouseButton1Up:Connect(function() text.Text = "Dudes take my picture-" end) end if text.Text == "Dudes take my picture-" then button.MouseButton1Up:Connect(function() text.Text = "-ugh" MuscleValue.Value = 2 end) end
Try using WaitForChild on MuscleOn.
The first problem i noticed:
Humanoid:LoadAnimation
is deprecated. You should insert an animator into the humanoid, and use Animator:LoadAnimation
instead. But Im pretty sure this isn't the reason your script isn't working
The second problem i noticed:
You use an if statement
, which only checks once. It would be better to use the Changed event
to determine when the textlabel is changed, and if the text is the desired.
Ex;
text.Changed:Connect(function(property) -- changed event if property == "Text" then -- if the text changed if text.Text == "Its the hammer, hes real!" then button.MouseButton1Up:Connect(function() text.Text = "Dudes take my picture-" end) elseif text.Text == "Dudes take my picture-" then -- combining the if statements button.MouseButton1Up:Connect(function() text.Text = "-ugh" MuscleValue.Value = 2 end) end end end)
Hope this helps and if not I hope it leads you in the right direction :)