Big Script doesnt work

So,I am doing a normal script for the tutorial. But from line 8 to line 20 nothing works. This is script. It should turn on the music when player pressed the button, but if playing false it doesn’t work. And with true the music starts playing without pressing the button.

local button = script.Parent

button.MouseButton1Click:Connect(function()
	while wait(0.2) do
		script.Parent.BackgroundColor3=Color3.fromHSV(math.random(100)/100,1,1)
		script.Parent.Text ="Rickroll!"	 
		
local Sound = game.SoundService.Sound
		local played = false
		button.MouseButton1Click:Connect(function()
			if played == false then
				
		game.SoundService.Sound:Play()	
		played = true
				print("wut")
				
			end
		end)
	end
end)

Bye!

1 Like

This is Explained on the script eh

local Button = script.Parent -- Ur Button Location

--Keeping the Original Values will changed on the function as if the activation back to false or turn off
local OriginalColor = Instance.new("Color3Value", Button) 
OriginalColor.Value = Button.BackgroundColor3

local OriginalText = Instance.new("StringValue", Button)
OriginalText.Value = Button.Text
----------------------------------------------------------------------------

local Activated = false -- Activation

Button.MouseButton1Down:Connect(function() -- Function
	
	local Sound = game.SoundService.Sound -- Ur Sound location
	
	if Activated == false then -- Confirming if the activation 
		
		Activated = true -- making the activation true cuz its running right now
		
		Sound:Play() -- Playing the sound as the activation true
		
		Button.Text = "RickRoll!" -- The Text On The Function
		
		repeat -- repetition for the background changing color
			wait(0.2)
			Button.BackgroundColor3 = Color3.fromRGB(math.random(1, 255), math.random(1, 255), math.random(1, 255)) 
		until -- stops when the activation is now false
		Activated == false
		
	else
		Activated = false -- Turning the activation to false for pressing again which stops the function
		
		Sound:Stop() -- Stops the sound as the activation false 
		
		-- Applying the original properties changed on the function
		wait(0.3) -- Delation for the loop changing color cuz the loop changing color still might running and wont back the button original color
		Button.BackgroundColor3 = OriginalColor.Value 
		Button.Text = OriginalText.Value 
		
	end
end)
1 Like

Nothing changed. Maybe make another script?

I really dont know whats the error but did you try putting them in the exact location
cuz it works perfectly fine to me eh

1 Like