I made a script that makes it so that when a player clicks on my selected model, it plays a sound How can i make it so that after a player clicks on the part once it does not play again when clicking on it a second time?
basically can i make it so that each player can play the sound once
This is the script I'm currently using:
Brick = script.Parent Sound = Brick.Sound2 function onClicked() Sound:Play() end script.Parent.ClickDetector.MouseClick:connect(onClicked)
You say per player, which means other players should still be able to click it, so here's what I think should work for your use.
Brick = script.Parent Sound = Brick.Sound2 banned = {} -- Adds the ban list as a table so the script doesn't error. function onClicked(plr) for i,v in pairs(banned) do -- Checks the banned list for people not allowed to use the button. if v==plr.Name then return end end Sound:Play() table.insert(banned,#banned+1,plr.Name) -- Adds the player to the ban list end Brick.ClickDetector.MouseClick:connect(onClicked)
I tested this before I posted it and it worked so it should work on your game. All I did is add a list that keeps track of all of the players that have hit the button before and when someone clicks it goes through this list and checks to see if the player clicking is on the list, and if they are it won't play the sound, if they aren't it plays the sound and adds them to the list. If you want to reset the list just add a line "banned = {}" and the list will be cleared, and previously banned players will be able to press the button again.
function onClick() sound:Play() sound.Parent = nil end
You could enable PlayOnRemove and then remove the sound object when clicked on. If you plan to recycle the sound after a match ends or so, you could simply clone the sound back into the object.