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

How do I change the ID of a sound mid script?

Asked by 8 years ago

The code right here for some reason cycles through songs in test mode but plays a faint loop in game or when run on server. The output is spammed with- Sound failed to load 20:17:41.339 - Sound failed to load Workspace.Pianostool.Seat.Music : rbxassetid://253293108 but at first it says I am not authorized to access asset, please explain.

    --songs 
--1 209586150
--2 253293108
--3 154866720
--reaper5 was here.

ids={209586150,
    253293108,
154866720}
debounce=false
function musiccycle()
    debounce=true
for i=1,3 do
    local music=script.Parent.Music
    music.SoundId="rbxassetid://"..ids[i]
    music:Play()
    print(music.TimeLength)
    wait(music.TimeLength)
end
debounce=false
end
script.Parent.Music.MaxDistance=50

while debounce==false do
    print("False")
    musiccycle()
end

1 answer

Log in to vote
2
Answered by 8 years ago

Servers don't load sounds

So, here's the problem: TimeLength only works in LocalScripts. And why? The server simply doesn't load the sound - The clients do. Which is the Players. And therefore only LocalScripts know those kinds of things about it.

So how come a server can :Play() a sound?
When the server uses the :Play() method on a sound, it actually sends a request across the network to all of the clients for them to Play the sound. At which point, they load and play the sound, but they never tell the server about it. This means the server never knows if the sound is stopped, or how long the sound is.

As for your issue with it not being authorised, I'm sure there's a nice reasonable explanation along the lines of it not being authorised.

Ad

Answer this question