Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

for some reason the scripts merged when i posted this, the second script starts after line 15

2 answers

Try using WaitForChild on MuscleOn.

1 comment

0

thanks for the suggestion, that might've helped, but it still doesn't work.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.