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

This Sound Attack Script Won't Even Play? Help Please.

I Just Want It So It Play When The Player Gets Hurt

ID = {131138828,131138832,131138835}
script.Parent.HitSound.SoundId = "http://www.roblox.com/asset/?id="..ID
function onTouched(hit)
	script.Parent.HitSound:play()--change sound here to put your sound name--
end
script.Parent.Touched:connect(onTouched)

But For Some Reason Its Not Playing Please Help!

1 comment

0

well you didn't call which part value of the table meaning it doesn't know what to do. I think. like you have to do print(table[1]) or something like that then that would print the first variable.

2 answers

So you want to make so when a player touched that gets hurt it plays a sound?

Try doing this:

script.Parent.Touched:connect(function(hit) --Find the humanoid that touched the part.
hit.Parent.Humanoid.Changed:connect(function() --If the hum lost hp when touching te part do...
script.Parent.HitSound:Play() --Play the sound.
end) --Defenitly not an elephant.
end) --Defenitly not jeff.

If you want to make it play random sounds when touched then I recomend you using math.random. You can see how math.random works on shitty AlvinBlox's videos. Hope I helped.

The problem is that you are trying to concatenate a table with a string.

your ID variable is a table.

the SoundId should be a string.

To fix your problem, get the id that you want to play when a player gets hit. I will use ID[1] for example:

--          index #1   index #2    index #3
local ID = {131138828, 131138832, 131138835}
script.Parent.HitSound.SoundId = "rbxassetid://"..ID[1]
function onTouched(hit)
    script.Parent.HitSound:Play()
end
script.Parent.Touched:connect(onTouched)

I hope this helped

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