Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to crop a sound?

So I made this script:

function onPlayerAdded()
	local RandNum = Instance.new("NumberValue")
	RandNum.Value = math.random(10)
	for i,v in pairs(game.Players:GetChildren()) do
		if v:IsA("Player") then
			RandNum.Parent = v
			RandNum.Name = "RandomNumber"
				if RandNum.Value <= 3 then
					game.Workspace.Sounds.Firework:Play()
					local LuckMessage = Instance.new("Message", game.Workspace)
						LuckMessage.Text = RandNum.Parent.Name .. " got lucky! Good job!"
						wait(5)
						LuckMessage:Destroy()
				elseif RandNum.Value >= 8 then
					local UnLuckMessage = Instance.new("Message", game.Workspace)
						game.Workspace.Sounds.Suspense:Play()
						UnLuckMessage.Text = RandNum.Parent.Name .. " got unlucky. Sorry."
						wait(5)
						UnLuckMessage:Destroy()
							local UnLuckExplode = Instance.new("Explosion")
								for i,v in pairs(game.Workspace:GetChildren()) do
									if v:IsA("Model") then
										UnLuckExplode.Parent = v.Torso
								end
						end
				end
		end
	end
end

game.Players.PlayerAdded:connect(onPlayerAdded)

for _,v in pairs(game.Players:GetChildren()) do
	if v:IsA("Player") then
		onPlayerAdded()
	end
end

And the Firework sound effect just goes on too long. If I try to put a wait(18) there, then it will delay the message. Can someone help me? Thanks! :)

2 answers

✓ Accepted answer

You'd put:

delay(18, function()
	sound:Stop()
end)

Basically, what that does is wait a number of time, then call the function.

Hope this helps! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.