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

This script only works sometimes?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So I have this script put into bricks so that when they are clicked, a sound will play. The problem is, it only works sometimes, at random intervals.

-- This script goes into a ClickDetector within a part.

local function onMouseClick(Player)
    if not Player.PlayerGui:findFirstChild("ClickAudio") then 
        local ls = Instance.new("Sound")
        local length = 1 -- How long the sound plays before removed.

        ls.SoundId = "http://www.roblox.com/asset/?id=" -- Audio id here.
        ls.Name = "ClickAudio"
        ls.Volume = 0.5
        ls.Pitch = 1
        ls.Parent = Player.PlayerGui
        ls:Play()

        game:GetService("Debris"):AddItem(ls, length)
    end
end
script.Parent.MouseClick:connect(onMouseClick)

The audio will play, but not all of the time. And I can't just spam the button a bunch of times, because it won't play. I have to wait a few minutes and try again, and it still might not work.

4 answers

Log in to vote
1
Answered by 10 years ago

-- This script goes into a ClickDetector within a part. local function onMouseClick(Player) if not Player.PlayerGui:findFirstChild("ClickAudio") then local ls = Instance.new("Sound") local length = 100 -- How long the sound plays before removed. ls.SoundId = "http://www.roblox.com/asset/?id=" -- Audio id here. ls.Name = "ClickAudio" ls.Volume = 1 ls.Pitch = 1 ls.Parent = Player.PlayerGui ls:Play() game:GetService("Debris"):AddItem(ls, length) end end script.Parent.MouseClick:connect(onMouseClick)

This Should work!

Ad
Log in to vote
1
Answered by 10 years ago

Add "wait(2)" on line one. Instant scripts = nono

Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
10 years ago

Do you even have your audio id in the script. It's also recommended to have the volume at 1, roblox glitches sometimes.

Log in to vote
-1
Answered by 10 years ago

Lmao Free Modeled You can tell cause he didn't put the 'ID'.

Answer this question