I want to make a spray can play a spray sound when the player clicks left mouse button
the problem is that the sound loops badly
this is the code:
function SetLength(sound, length)
sound.PlaybackSpeed = sound.TimeLength/length
end
sprayCan.Equipped:Connect(function()
sound = script["Spray Paint 8 (SFX)"]
spray = script["Aerosol Spray Can 3 (SFX)"]
shake = script.Parent.Shake
shakeAnim = Character.Humanoid:LoadAnimation(shake)
hold = script.Parent.Hold
holdAnim = Character.Humanoid:LoadAnimation(hold)
shakeAnim:Play()
sound.PlaybackSpeed = 1.5
sound:Play()
shakeAnim.Ended:Wait()
--the sound must be loaded, therefore it only works on the client
holdAnim:Play()
equipped = true
end)
sprayCan.Unequipped:Connect(function()
equipped = false
holdAnim:Stop()
spray:Stop()
end)
while wait() do
local pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
if pressed then
if equipped then
if not spray.Playing then
load = spray.IsLoaded or spray.Loaded:Wait()
SetLength(spray, .5) --34 is the new length(in seconds)
spray:Play()
end
calculateSprayInfo()
end
else
if spray ~= nil then
if spray.Playing == true then
spray:Stop()
end
end
end
end