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

Why is my alarm script erroring? anyone available to help?

I tried this code, and it probably "Is" supposed to work.

script.Parent.MouseClick:Connect(function()
	if script.Parent.Name == "ClickDetector" then
		for i,v in pairs(workspace:GetChildren()) do
			if v.Name == "CDZ_ALARM" then
				v.BrickColor = BrickColor.new("Really red")
				v.Sound:Play()
			else
				v.Sound:Stop()
				v.BrickColor = BrickColor.new("Really black")
			end
		end
		
	end
end)

Error: 18:05:28.562 - Sound is not a valid member of Camera

6 comments

0

What is "CDZ_ALARM"? Is it a part or sound?

0

Also what are you trying to accomplish with this script?

0

Its inside a part, and its a sound. What i am trying to accomplish is its for a alarm system, for a place called "CDZ" Class D Zone. And if there is a breach, the zone is locked down to ensure the safety of the CD.

0

Is there an object under workspace named "CDZ_ALARM"? If not, then the script won't work.

0

You have to put a if statement with else (elseif). Without the if statement, the script will attempt to find the Sound in all of it's children (such as the Camera)

0

If my answer satisfies your question, please accept it.

1 answer

✓ Accepted answer

Basically, if the player clicks an object that is a part that has a sound titled "CDZ_ALARM" within it, the part turns really red and the sound starts playing:

local debounce = false --A debounce would be useful for a script like this.

script.Parent.MouseClick:Connect(function()
	if debounce == false then
		debounce = true
        for _, v in pairs(workspace:GetChildren()) do
            if v:FindFirstChild("CDZ_ALARM") then
                v.BrickColor = BrickColor.new("Really red")
                v.CDZ_ALARM:Play()
			else
				return
			end
        end
		debounce = false
    end
end)

3 comments

2

How long do you want the alarm to stay until it goes off? I'll edit my answer once you tell me.

0

If its clicked again, it turns off.

0

But i really appreciate you helping me, so i'm accepting your answer. Happy scripting! :D

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