In my game, if you get hit multiple times by something, it makes sound really loud and it sounds awful. I was wanting to know if it was possible to make it play every 3 seconds. Such as if you get hit 3 times in a single second, the sound still plays. But if the projectile damages you every 3 seconds, then it plays every 3 seconds. What I'm trying to say is, the sound doesn't play every single time you're hit. It's a 3 second interval to prevent sound oddness I guess you could call it. Also is it possible to make it play a different sound depending on how much damage you take? Like if you take 50-199 (My game's max health goes to 200) damage it plays this sound: http://www.roblox.com/Player-WoundWeak01-item?id=156532212

Here's the code:


Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=155675172") 
local lastHealth = {}
function onPlayerAdded(ply)
local f = function (humanoid)
lastHealth[humanoid] = humanoid.Health
humanoid.Changed:connect(function(prop)
if prop == "Health" then
local lh = 0
pcall(function ()
lh = lastHealth[humanoid] or 0
end)
if lh > humanoid.Health then 
local sound1 = Instance.new("Sound", humanoid.Parent.Torso)
sound1.SoundId = "http://www.roblox.com/asset/?id=155675172"
sound1.PlayOnRemove = true
sound1:Destroy()
end
lastHealth[humanoid] = humanoid.Health
end
end)
end
ply.CharacterAdded:connect(function (char)
while char:FindFirstChild("Humanoid") == nil do wait() end
f(char.Humanoid)
end)
end

game.Players.PlayerAdded:connect(onPlayerAdded)
for i,v in pairs(game.Players:GetPlayers()) do onPlayerAdded(v) end 

1 comment

0

What the heck, script kiddie with luck turns into big dev and manages to be the 6969'th question 0_O