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

OnClick play audio isn't working?

Asked by 6 years ago

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)

2 answers

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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.

Ad
Log in to vote
0
Answered by 6 years ago

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)
0
dude the guy already answered it so ya.. moncefci3 -3 — 6y

Answer this question