I'm trying to make a door that'll sound an alarm when It's touched, but only for non-group members. Whenever you walk through it nothing happens at all; nothing pops up in the output either. I also have a button that will play the sound when clicked, but only when the value is false, and if it is true, it'll stop the sound. Here's my script:
game.Players.PlayerAdded:Connect(function(Player) local Rank = Player:GetRankInGroup(3738720) local debounce = false local Assets = script.Parent.Assets local Scan = Assets.Scan local Hum = Assets.Hum local Alarm = Assets.Alarm local Light1 = script.Parent.Light1 local Light2 = script.Parent.Light2 local Light3 = script.Parent.Light3 local Scanner = script.Parent.Scanner local Enabled = Assets.Enabled local Disabler = script.Parent.Disable.ClickDetector Alarm.Parent = workspace Disabler.MouseClick:Connect(function() Enabled = false end) Disabler.MouseClick:Connect(function() if Enabled == false then Enabled = true end end) Scanner.Touched:Connect(function() if debounce == false then debounce = true Scan:Play() wait(.6) if Rank >= 1 then Enabled = true Enabled.Changed:Connect(function() if Enabled == true then workspace.Alarm:Play() print("True") if Enabled == false then workspace.Alarm:Stop() print("False") end end debounce = false end) end end end) end)
Thanks if you can help me out, it would help!
The reason that this isn't work because Touched doesn't have any input. It needs at least one.
I think this is a fix. The problem is in between lines 34 and 58.
Scanner.Touched:connect(function(hit) if debounce == false then if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Name == Player.Name then if Rank <= 1 then Enabled = true Enabled.Changed:connect(function(val) if Enabled == true then workspace.Alarm:Play() print("true") end if Enabled == false then workspace.Alarm:Stop() print("false") end Debounce = false end) end end end end end) end)
There is most likely a way to shorten this. If this does not work, I apologize.