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

Why doesn't this death script work?

Asked by
Zerio920 285 Moderation Voter
10 years ago
local player = game.Players.LocalPlayer
repeat wait() until player:FindFirstChild("leaderstats")
    local lives = player.leaderstats.Respawns
    player.CharacterAdded:connect(function(character)
        character:FindFirstChild("Humanoid").Died:connect(function()
            wait()
            lives.Value = lives.Value - 1
            player:FindFirstChild("Backpack").Death:Play()
            wait(1)
            children = player.Backpack:GetChildren()
            for _,v in pairs(children) do
                if v:IsA("Sound") then
                    repeat
                        wait()
                        v:Stop()
                    until v.IsPlaying == false 
                end
            end
        end)
    end)

This is in a LocalScript in the Starterpack (a LocalScript will help me the best, so don't suggest a server script). It's supposed to cut off 1 life from your stats, and play a sound. It does neither of these, for some reason.

0
Any errors? PiggyJingles 358 — 10y
0
No, the Output window doesn't show anything wrong. Zerio920 285 — 10y

2 answers

Log in to vote
1
Answered by 10 years ago

I kind of remade your script, the coding is untested, but I think it works (Sorry if didn't help, bit tired. ;-; );

repeat wait(0) until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") and script and script.Parent and game.Players.LocalPlayer:FindFirstChild("leaderstats") and game.Players.LocalPlayer.leaderstats:FindFirstChild("Respawns") and game.Players.LocalPlayer:FindFirstChild("Death")

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char.Humanoid
local stats = plr.leaderstats
local respawns = stats.Respawns

wait(0)
plr.Death:Stop() --This will stop the Sound named 'Death' from looping/playing when the player respawns (Within LocalPlayer)
wait(0)

local function onDeath()
if hum.Health <= 0 then
if respawns.Value > 0 then
respawns.Value = respawns.Value - 1
for i,v in pairs(plr:GetChildren()) do if v:IsA("Sound") then repeat wait(0) v:Stop() until v:Stop() or not v.IsPlaying end end
plr.Death:Play()
else
print("Out of respawns")
for i,v in pairs(plr:GetChildren()) do if v:IsA("Sound") then repeat wait(0) v:Stop() until v:Stop() or not v.IsPlaying end end
plr.Death:Play()
-- Rest of coding
end
end
end;

hum.Changed:connect(onDeath);

Sorry if wasn't very useful, didn't explain well, coded the code wrong, or the code didn't work, a bit tired tonight for some reason. ;-; Hope this helped!

0
Not too sure if checking if the Humanoid's health is equal to 0 works, since the main cause of death in my game is by falling off the map or having your body parts destroyed. Haven't tested yet though so I'll get back to you on that. Zerio920 285 — 10y
0
I know, I'm now testing the script aswell, and I've already found multiple errors, I'm going to edit the script allot more to that it will work for you bro, rest assured. :) TheeDeathCaster 2368 — 10y
0
Ah, thanks so much :) Zerio920 285 — 10y
0
Ok, I posted a tested code, if you have any questions, just let me know. :) TheeDeathCaster 2368 — 10y
View all comments (3 more)
0
Still doesn't work for some reason. Btw like I mentioned, the main cause of death is falling so that might have something to do with it. Also there's no "music" in the player, I removed that part just so you know. Zerio920 285 — 10y
0
Oh, sorry. ;-; I like to add the music into the Player instead of the Backpack then because I won't have to keep getting the whole thing re-inserted again, to keep it from starting it over also. TheeDeathCaster 2368 — 10y
0
I created a place where you can test out the script and see how it works/is set up; http://www.roblox.com/TheeDeathCasters-Place-Number-325-place?id=172724478 Hope this helped bro! :) TheeDeathCaster 2368 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

Maybe try putting it in lighting instead. Thats what I think but im not no pro scripter.

0
Why would that work? Also, it has to be in a LocalScript, and LocalScripts have to be somewhere in the Starter section so every player has one. Zerio920 285 — 10y
0
Idk. I said im not a pro scripter! AWESOMEnoob3 3 — 10y
0
It's fine if you don't know the answer, just don't try to answer something you aren't completely experienced with. Zerio920 285 — 10y

Answer this question