Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Any part of my scripts that has to do with a certain value doesnt work, but there are no errors?

Asked by 3 years ago

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
0
for some reason the scripts merged when i posted this, the second script starts after line 15 surviarlTheJefkillre 55 — 3y

2 answers

Log in to vote
1
Answered by
kjljixx 42
3 years ago

Try using WaitForChild on MuscleOn.

0
thanks for the suggestion, that might've helped, but it still doesn't work. surviarlTheJefkillre 55 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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 :)

Answer this question