Sound not sending threw and playinjg?

So i wanna send a sound object that was randomly picked from a client to a sever back to a client, but its not working when trying to play the sound sent to the last, any help?

local sound = nil

local maxLoudness = 10

local function prop()

sound:Play()

end

while wait(1) do

if sound ~= nil then

prop()

end

end

script.Parent.Parent.NumberSound2.OnClientEvent:Connect(function(noise)

sound = noise

end)

The sound is a Sound object or a Sound id?

Its an object, randomly picked in the first local script.

Try using PreloadAsync to make sure the sound you receive is loaded.

2 Likes

It is, its just not playing when its supposed to.

hmm, I recommend playing the sound when the Event is fired, instead of making a loop checking if there is a sound.

script.Parent.Parent.NumberSound2.OnClientEvent:Connect(function(noise)
   if noise:IsA("Sound") and noise.SoundId ~= nil then
       noise.Parent = game.Players.LocalPlayer
       noise:Play()
   end
end)

Well, im gonna send the whole script to try understand.

local sound = nil

local maxLoudness = 10

local function prop()

sound:Play()

end

while wait(1) do

if sound ~= nil then

prop()

end

end

script.Parent.Parent.NumberSound2.OnClientEvent:Connect(function(noise)

sound = noise

end)

while true do

print("repeats sound thing")

local amplitude = math.clamp(sound.PlaybackLoudness/600, 0.2, 0.4)

script.Parent.Size = UDim2.new(amplitude, 0, amplitude, 0)

wait(0.005)

end

Hmmmmmmmm… I would recommend rewriting the code from scratch and avoiding while loops, they aren’t a really good practice. Instead of sending a sound, send the SoundId and then create a new Sound Instance and set its id to the received id.

Wym, im a little confused, It used to play fine up until I made it have to find the sound.