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

A script of mine works in solo, but not online?

Asked by
gkku 10
10 years ago

Earlier today a friend of mine requested a few scripts, and I went ahead and made them because I've only started cracking down on learning Lua earlier this year and really needed the practice.

One of these scripts was pretty simple - make a sound play when a part is touched. After a while I had whipped this up.

local playing = false

function MakeSound()
    if playing == false then
        local sound = Instance.new("Sound")
        sound.Parent = script.Parent
        sound.SoundId = "http://www.roblox.com/asset/?id= " --Sound ID goes here
        sound:Play()
        playing = true
        wait(1)
        playing = false
        sound:Destroy() --can't leave all these played sounds laying around
    elseif playing == true then return
    end
end

script.Parent.Touched:connect(MakeSound)

For some reason it worked in solo, but not online. I realized I over-complicated it so I changed it to simply play a pre-existing sound when touched, and now it works online.

But I'm curious just in case this problem ever arises again in my scripts... what IS the problem? Why'd it work in solo but not online?

0
Did you forget to append a soundId on line 7? Merely 2122 — 10y
0
Even with a SoundId set it worked in solo, but not online when we tested it. Also I feel like I didn't make it clear but I have a fix, it's just I don't know why this over-complicated iteration of it didn't work online. gkku 10 — 10y
0
Is it activating or not (ex: sound is not being created)? FromLegoUniverse 264 — 10y
0
I'm not sure, is there any kind of in-game explorer so I can see what it's doing online? gkku 10 — 10y
0
Well thanks for trying to help me understand what's wrong, but considering someone here described a very similar problem I'm just going to chalk it up as being a quirk with sound. gkku 10 — 10y

1 answer

Log in to vote
-4
Answered by
Kratos232 105
10 years ago

Try using it as a LocalScript.

  • Kratos232
0
That worked, but I had to pretty heavily modify everything so it didn't answer my problem: I don't understand why that script in the OP (with a SoundId set of course) works when testing in solo with studio, but not online. gkku 10 — 10y
Ad

Answer this question