No reason this shouldn't work

So I was making a script:

script.e.Changed:Connect(function()
	if script.e.Value == true then
		script.Parent.Sound:Play()
		coroutine.wrap(function()
			if script.e.Value == false then
				script.Parent.Sound:Stop()
				script.Parent.Material = Enum.Material.Glass
				return
			end
			script.Parent.Material = Enum.Material.Neon
			wait(script.Parent.Sound.TimeLength)
			script.Parent.Material = Enum.Material.Glass
			wait(script.Parent.Sound.TimeLength)
		end)()
	end
end)

And it just doesn’t work. i’ve tried putting a print and its not even firing when E changes. What do i do?

1 Like

Maybe because of the extra parentheses in line 14?:

end)()
1 Like

provide more context?
edit: i assume e is a boolValue, right?

1 Like

yes a boolvalue uysgdifuyhgasdfhgasdhfgkajshdfgjkashd

1 Like

i dont really recommend using somethingValue since now attributes exist, although, try the following: (this is line 1)

script.e:GetPropertyChangedSignal("Value"):Connect(function()
1 Like

if you add extra parenthesis on the end of coroutine.wrap() it’ll execute immediately after calling so prob not
edit: more about this here

2 Likes

did bro really use AI to generate this :sob:

2 Likes

Is this a Script or a LocalScript, And try this script

script.e.Changed:Connect(function()
    print("It worked")
	if script.e.Value == true then
		script.Parent.Sound:Play()
		coroutine.wrap(function()
			if script.e.Value == false then
				script.Parent.Sound:Stop()
				script.Parent.Material = Enum.Material.Glass
				return
			end
			script.Parent.Material = Enum.Material.Neon
			wait(script.Parent.Sound.TimeLength)
			script.Parent.Material = Enum.Material.Glass
			wait(script.Parent.Sound.TimeLength)
		end)()
	end
end)

Is it printing “It worked”?

1 Like

Use coroutine.create() and see if that does anything.
Here’s the code in coroutine.create()

script.e.Changed:Connect(function()
	if script.e.Value then
		script.Parent.Sound:Play()
		local waitTime = script.Parent.Sound.TimeLength
		
		local coro = coroutine.create(function()
			if not script.e.Value then
				script.Parent.Sound:Stop()
				script.Parent.Material = Enum.Material.Glass
				return
			end
			script.Parent.Material = Enum.Material.Neon
			wait(waitTime)
			script.Parent.Material = Enum.Material.Glass
			wait(waitTime)
		end)
		
		coroutine.resume(coro)
	end
end)
1 Like

A little more information is probably needed - where is the script located? where are you changing the value of e
If this is a ServerScript and your changing the value of e from a Client then the Server will not pick up the change.

1 Like

Tried this didn’t work. the new script:

script.e:GetPropertyChangedSignal("Value"):Connect(function()
	if script.e.Value == true then
		script.Parent.Sound:Play()
		coroutine.wrap(function()
			if script.e.Value == false then
				script.Parent.Sound:Stop()
				script.Parent.Material = Enum.Material.Glass
				return
			end
			script.Parent.Material = Enum.Material.Neon
			wait(script.Parent.Sound.TimeLength)
			script.Parent.Material = Enum.Material.Glass
			wait(script.Parent.Sound.TimeLength)
		end)()
	end
end)

also, for anyone needing additional information, the script is a server script housed in a part in a folder in the workspace.

i also added an attribute called enabled and tried:

script.Parent:GetAttributeChangedSignal("enabled"):Connect(function()
	print("It worked!!!")
	if script.Parent:GetAttribute("enabled") == true then
		script.Parent.Sound:Play()
		coroutine.wrap(function()
			if script.Parent:GetAttribute("enabled") == false then
				script.Parent.Sound:Stop()
				script.Parent.Material = Enum.Material.Glass
				return
			end
			script.Parent.Material = Enum.Material.Neon
			wait(script.Parent.Sound.TimeLength)
			script.Parent.Material = Enum.Material.Glass
			wait(script.Parent.Sound.TimeLength)
		end)()
	end
end)

and it didn’t print

1 Like

Did you change the attribute’s value when testing? AFAICS nothing’s wrong here unless the script isn’t enabled
Video below of replicating your issue (no issues)
[0313.mp4 - Google Drive]

1 Like

yes the script is enabled. yes i enabled the attribute during testing. maybe its just a glitch

1 Like

Could you test it with another part?

I did. Just flat out nothing. i made sure it had an attribute and a sound and the exact same script.

Try:

Change: script.e:GetPropertyChangedSignal("Value"):Connect(function()

To: script.e.Changed:Connect(function()

so it just randomly started working. like i logged on today and it was working without changing anything so

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.