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)
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.