This is a local script in StarterGui. When I run this, no error is given and the sounds don't even get copied into the humanoid.
"Sound1" and "Sound2" are sounds and children to the local script below.
player = game.Players.LocalPlayer function Use(u) z = script.u:Clone() z.Parent = player.Character.Humanoid z:Play() end play = true while play do if player.Character.Humanoid.Health == 0 then play = false if player.TeamColor == "Bright Blue" then Use(Sound1) else Use(Sound2) end play = true end end
You're telling the script to find an object named "u" inside the script. What you want to do instead of using a period, you want to use brackets, which allow you to do things similar to :FindFirstChild(). However, they can break the script if the object doesn't exist. So make sure that object exists! Here's what I did to your script (Note: Brackets take in strings, so I had to modify the code that calls the function):
player = game.Players.LocalPlayer function Use(u) local z = script[u]:Clone() --Make it local. It's only used in the function and it can reduce lag z.Parent = player.Character.Humanoid z:Play() end play = true while play do if player.Character.Humanoid.Health == 0 then play = false if player.TeamColor == "Bright Blue" then Use(Sound1.Name) else Use(Sound2.Name) end play = true end wait() --Add a wait() here to prevent the ROBLOX servers from overloading end
Also, one more tip, use tabs to organize your code like I did. Spaces make it more difficult to keep it organized and spot errors.
I am just adding on to the last guys. you have to add BrickColor.new("color") for it to work . e.e.
player = game.Players.LocalPlayer function Use(u) local z = script[u]:Clone() --Make it local. It's only used in the function and it can reduce lag z.Parent = player.Character.Humanoid z:Play() end play = true while play do if player.Character.Humanoid.Health == 0 then play = false if player.TeamColor == BrickColor.new("Bright Blue") then Use(Sound1.Name) else Use(Sound2.Name) end play = true end wait() --Add a wait() here to prevent the ROBLOX servers from overloading end