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

Regarding my touch button, help with audio?

(Sorry if I went against the rules in my previous question, made sure to read them again!)

Okay, so I wanted to make a touch button that once made contact with a player, changes the game audio and resets all players and then after 30 seconds, music changes back to normal. Here is what I've got so far...

This script successfully kills the player that makes contact with the Part, however, I haven't tested it to see if it kills all players at once. If there is a way to kill all players at once, please let me know what I have to add or change for that to happen.

 local part = Instance.new('Part')
 part.Anchored = true
 part.Parent = workspace
 part.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		hum.Health = 0
	end
 end)

 for i, player in ipairs(game.Players:GetPlayers()) do
	if player.Character then
		local hum = player.Character:FindFirstChild('Humanoid')
		if hum then
			hum.Health = 0
		end
	end
 end

 local part = script.Parent
 part.Touched:connect(function(hit)
	if hit.Parent then
		local hum = hit.Parent:FindFirstChild("Humanoid")
		if hum then
			hum.Health = 0
		end
	end
 end)

The script named "Auto-Install" successfully plays sound 1 but does not change its audio to sound 2 once the Part is touched. I figured this is because I haven't included the second audio in the script, however, I don't know how to. Bear in mind these are normal scripts, not local. This is how my Explorer looks - I don't know if everything is in the right place?

V Workspace
      Camera
      Terrain
      Sound2      -- not sure where this belongs
      SpawnLocation
      V Cindering's Background Music Tool
            V Global Background Music      -- folder
                  Sound1
            INSTRUCTIONS      -- script
            Auto-Install      -- script: plays sound1
            Settings
     V Part
           Script      --script: the script that kills the player when touching the part

Any help very much appreciated! Thanks.

1 comment

0

This is better :)

1 answer

✓ Accepted answer

Simple, what you did is put the code for killing all players, outside of the Touched Event

do this:

local Players = game:GetService('Players')

local part = script.Parent -- define part here

local sound = script.Parent.Sound -- define sound here

part.Touched:connect(function(hit)
	for i, v in ipairs(Players:GetPlayers()) do
		if v.Character and v.Character.Humanoid.Health > 0 then
			v.Character.Humanoid.Health = 0
		end
	end
	sound:Play()
	wait(30)
        sound:Stop()
end)

i don't know how cinderings music thing works but figure out how to get the other sound to stop

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