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

How do I fix this death script?

Asked by
Zerio920 285 Moderation Voter
10 years ago

This is in a server script:

01game.Players.PlayerAdded:connect(function(player)
02 
03    repeat wait() until player:FindFirstChild("leaderstats")
04    local lives = player.leaderstats.Respawns
05 
06    player.CharacterAdded:connect(function(char)
07        char:FindFirstChild("Humanoid").Died:connect(function()
08            lives.Value = lives.Value - 1
09 
10            player:FindFirstChild("Backpack").Death:Play()
11            children = player.Backpack:GetChildren()
12            for _,v in pairs(children) do
13            if v:IsA("Sound") then
14            v:Stop()
15            v:Destroy()
View all 21 lines...

What I'm attempting to do here is two things: Remove one life from the player when he dies, as well as play a "death" sound. The problem is that this rarely works online for some reason. I tried a local script too but it doesn't seem to work. It could be a problem with the script or there might be some other way to do this that I'm not aware of. Any ideas?

0
What is it not doing that it should be doing? GoldenPhysics 474 — 10y
0
Both aspects of the script don't seem to work. No lives are removed and the sound doesn't play. Zerio920 285 — 10y

2 answers

Log in to vote
2
Answered by
acecateer 130
10 years ago

It seems to work fine when I tested it with a server, it does not seem to work as good whilst playing solo mode. I think it should work fine on online mode.

01local time = 10 --How long you want the music to play, you're making it play then immediately stopping the sound.
02 
03game.Players.PlayerAdded:connect(function(player)
04    repeat wait() until player:FindFirstChild("leaderstats")
05    local lives = player.leaderstats.Respawns
06    player.CharacterAdded:connect(function(character)
07        character:FindFirstChild("Humanoid").Died:connect(function()
08            wait()
09            lives.Value = lives.Value - 1
10            player:FindFirstChild("Backpack").Death:Play()
11            wait(time)
12            children = player.Backpack:GetChildren()
13            for _,v in pairs(children) do
14                if v:IsA("Sound") then
15                    repeat --This makes sure the sound stops completely. Roblox's sound system is a bit buggy.
View all 23 lines...
Ad
Log in to vote
0
Answered by 10 years ago

For the sound aspect, try adding a wait of however long the sound plays for. From my beginner standpoint it appears as soon as it is told to Play it is told to Stop.

Answer this question