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.
01 | player = game.Players.LocalPlayer |
02 |
03 | function Use(u) |
04 | z = script.u:Clone() |
05 | z.Parent = player.Character.Humanoid |
06 | z:Play() |
07 | end |
08 |
09 | play = true |
10 |
11 | while play do |
12 | if player.Character.Humanoid.Health = = 0 then |
13 | play = false |
14 | if player.TeamColor = = "Bright Blue" then |
15 | Use(Sound 1 ) |
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):
01 | player = game.Players.LocalPlayer |
02 |
03 | function Use(u) |
04 | local z = script [ u ] :Clone() --Make it local. It's only used in the function and it can reduce lag |
05 | z.Parent = player.Character.Humanoid |
06 | z:Play() |
07 | end |
08 |
09 | play = true |
10 |
11 | while play do |
12 | if player.Character.Humanoid.Health = = 0 then |
13 | play = false |
14 | if player.TeamColor = = "Bright Blue" then |
15 | Use(Sound 1. Name) |
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.
01 | player = game.Players.LocalPlayer |
02 |
03 | function Use(u) |
04 | local z = script [ u ] :Clone() --Make it local. It's only used in the function and it can reduce lag |
05 | z.Parent = player.Character.Humanoid |
06 | z:Play() |
07 | end |
08 |
09 | play = true |
10 |
11 | while play do |
12 | if player.Character.Humanoid.Health = = 0 then |
13 | play = false |
14 | if player.TeamColor = = BrickColor.new( "Bright Blue" ) then |
15 | Use(Sound 1. Name) |