Hello i would like to know if its possible to make audio play on local, only the player who clicks the part hears it, the local script i am using right now that doesn't work:
function onClicked() local x=script.Lol x:play() wait(14) end script.Parent.ClickDetector.MouseClick:connect(onClicked)
We can do this by using a remoteevent
First create a remoteevent and place it somewhere like the workspace or inside the clickdetector
Now let's work on the Script that fires when someone clicks, i will merge the function and where you call it together. Make sure you change the re variable to where the remoteevent is
local re = script.RemoteEvent script.Parent.ClickDetector.MouseClick:connect(function(plr) re:FireClient(plr) end)
I fired the remoteevent with the player
Next we will create a LocalScript inside startergui, also change the sound variable to where the sound is located inside the startergui, playing this will make it so that only the player can hear it. You will also need to point the re variable to where the remoteevent is located
local re = workspace.Part.ClickDetector.Script.RemoteEvent local sound = script.Parent.Sound re.OnClientEvent:connect(function() sound:Play() end)
When the remoteevent is fired towards the player the function will fire and it will play the sound. only the player who is firing the function can hear it because the sound is inside their playergui.
There is no variable for Lol in your script. You also need to locate the audio before calling it.
function onClicked() local x=script.Parent.Audio x:play() wait(14) end script.Parent.ClickDetector.MouseClick:connect(onClicked)