Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ROBLOX broke my injure sound script. Anyone want to help me fix it? *Please answer!!*

Asked by 10 years ago

Recently, ROBLOX fixed the sound bug, BUT in turn, it broke my script. If anyone knows how to get this to work, It'd be much appreciated. By the way, it's a script that plays a sound whenever you get injured.

I get this error in the output window, but I don't know if it has anything to do with my script:

14:46:14.775 - FMOD 36: An invalid object handle was used. 14:46:14.786 - FMOD 36: An invalid object handle was used.

Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=155675172") -- Prevents no sound playing the first time the player gets hurt
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 -- For solo mode testing.

Answer this question