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?
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)
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.
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)
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]