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

So I have a brick and if you click it. It makes sound and I want it to be able to only click once?

So I have a brick and if you click it. It makes sound and I want it to be able to only click once. Here is my script Brick = script.Parent Sound = Brick.Sound

function onClicked() Sound:Play() end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

How do I make it only click once?

1 answer

Once your mouseclick connects, it deletes the click detector; causing it to not function any more. Hope this helps in any way!

local cd = Instance.new("ClickDetector") -- Creates a click detector
local sound = Instance.new("Sound") -- creates sound

sound.SoundId = "Your soundID here" -- Put whatever soundID in between


cd.Parent = script.Parent -- Tells where you want to put the click detector, in this case; its inside the part
sound.Parent = script.Parent -- Tells where you want to put the sound, in this case; its inside the part

cd.MouseClick:Connect(function() -- Checks if you clicked, then run the code in between.
	sound:Play() -- Plays the sound
	cd:Destroy() -- Destroys click detector, making it a one time use.
end)

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