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

Custom dying sound not working ?

Asked by
Bulvyte 388 Moderation Voter
8 years ago

So i want my character play my "custom" sound when he dies and he can only hear it.

script that clones this in him

local Wasted = script.Wasted:Clone()

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:wait()
    Wasted:Clone().Parent = player
end)

script that should play when he dies ONLY FOR HIM...

Player = script.Parent.Parent.Parent.Parent.Character
Wasted = script.Parent

s = Player.Humanoid
    while true do
    if s.Health <= 0 then
    Wasted:Play()
   end
end

http://prntscr.com/8aqhj0 <<<< how my setup looks. is this right or is something wrong ? No errors in output tho... :/

1 answer

Log in to vote
3
Answered by
4Bros 550 Moderation Voter
8 years ago

I would recommend that you use a localscript for this and parent it into the starterpack and then put the Wasted audio inside the localscript. There is a custom event for humanoids that fire when they die, it's called Died, this is much more efficient to use than a while loop, and by the looks of the one you have in your script, your game should be crashing since there is no wait() inside of the loop.

--LOCALSCRIPT   put wasted audio inside this and put this script into starterpack--
local runservice = game:GetService'RunService'
local wasted = script:WaitForChild'Wasted'
repeat runservice.RenderStepped:wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild'Humanoid'

humanoid.Died:connect(function()
    wasted:Play()
end)






0
Dang, this is smart... Thank you anyway! I'll test this in the morning cuz now i gotta go sleep c: Bulvyte 388 — 8y
Ad

Answer this question