see here and here and here
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local music = player.PlayerGui.Musics.MusicOne
local musictwo = player.PlayerGui.Musics.MusicTwo
local humanoid = plr:WaitForChild("Humanoid")
if hit.Parent:FindFirstChild("Humanoid") then
if music.IsPlaying == false then
if musictwo.IsPlaying == false then
repeat wait () until music.IsPlaying == false and musictwo.IsPlaying == false
music:Play()
wait(104)
music:Stop()
wait(1.5)
musictwo:Play()
wait(85.5)
end
elseif music.IsPlaying == true or musictwo.IsPlaying == true then
music:Stop()
musictwo:Stop()
end
end
end)
New Code:
local part = script.Parent
debounce = false
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
local random = math.random(1,2)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local MusicOne = Instance.new("Sound", player)
MusicOne.SoundId = "rbxassetid://2218540019"
MusicOne.Name = "MusicOne"
local MusicTwo = Instance.new("Sound", player)
MusicTwo.SoundId = "rbxassetid://2588710875"
MusicTwo.Name = "MusicTwo"
if random == 1 then
MusicOne.Playing = true
else
MusicTwo.Playing = true
end
debounce = true
end
end)
part.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == true then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
for i,v in pairs(player:GetChildren())do
if v:IsA("Sound")then
v:Destroy()
end
end
debounce = false
end
end)
-- New Edites V.2
local SoundsInRegion = game.Workspace:WaitForChild("SoundsRegions")
local Found = false
while wait(1)do
for i,v in pairs(SoundsInRegion:GetChildren())do
Found = false
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts)do
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
print("Player was Found")
Found = true
break
else
Found = false
print("Player was not Found in region")
end
end
if Found == true then
if script.Parent.Sounds[v.Name].IsPlaying == false then
script.Parent.Sounds[v.Name]:Play()
break
end
else
script.Parent.Sounds[v.Name]:Stop()
end
end
end
5 comments
use a debounce
I would recommend having it so the script only plays while touching the brick or have a invisible walkthroughable brick that you can hit that plays it while touching that brick. That or try looking into some sound groups.
@KDarren12 I don't really know how. Could you help me?
I'll post some code to help, soon, today. There's a lot of things that could be going wrong, such as the music not completely loaded into the client..
better to use region3 for this but use whatever idc lol, use a debounce tho