Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question