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

How do I make to when a player dies, the Value of an Intalue, goes down by 1(minus 1)?

Asked by 4 years ago
Edited 4 years ago

I just need to make it to where when a player dies, the value goes down by 1. I'm currently making a minigame

local s = script.Stat
local vals = game.ReplicatedStorage.vals
t = 0
while true do
    t = 31
    repeat
        t = t-1
        s.Value = "Intermission: "..t.." second(s)"
        wait(1)
    until t == 0
    local mapselect = game.ReplicatedStorage.Games:GetChildren()
    local choose = math.random(1,#mapselect)
    curnum = 0
    for i =1,#mapselect do
        curnum = curnum +1
        if curnum == choose then
            mapselect[i]:Clone().Parent = workspace
            curmap = mapselect[i].Name
            s.Value = "Race Selected: "..mapselect[i].Name
    wait(2)
    s.Value = "Teleporting Players!"
        end
    end
    wait(3)
    local plrs = game.Players:GetChildren()
    for i = 1,#plrs do
        local num = math.random(1,32)
        plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
        plrs[i].Character.Parent = workspace.Ingame
        workspace.Ingame.Players.Value = workspace.Ingame.Players.Value + 1
    end
    t=10
    repeat
        t = t-1
        s.Value = "Game is starting in "..t.." second(s)"
        wait(1)
    until t == 0 
    s.Value = "GO!"
    wait(1)
    t=51
    repeat
        t = t-1
        s.Value = t.." second(s) left"
        wait(1)
    until t ==0 or workspace.Ingame.Players.Value ==0 or vals.Winner.Value ~= ""
    if vals.Winner.Value ~= "" then
        s.Value = vals.Winner.Value.. " has won!"
        game.Players[vals.Winner.Value].leaderstats.Coins.Value =game.Players[vals.Winner.Value].leaderstats.Coins.Value + 50000000
        game.Players[vals.Winner.Value].leaderstats.Wins.Value =    game.Players[vals.Winner.Value].leaderstats.Wins.Value + 1
        vals.Winner.Value = ""
    else
        s.Value = "No one has won!"
    end
    wait(3)
    local ingame = workspace.Ingame:GetChildren()
    for i =1,#ingame do
        local plr = game.Players:GetPlayerFromCharacter(ingame[i])
        plr:LoadCharacter()

    end
    workspace[curmap]:Destroy()
end

2 answers

Log in to vote
0
Answered by
Ankur_007 290 Moderation Voter
4 years ago

You can use some simple connections to achieve this as such:

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        -- Make a new connection each time the character spawns
        local humanoid = character:WaitForChild("Humanoid", 10)
        humanoid.Died:Connect(function()
            -- Decrease IntValue value
            YourIntValueHere.Value = YourIntValueHere - 1
        end)
    end)
end)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
for i,v in pairs(game.Players:GetChildren()) do
v.Character:WaitForChild("Humanoid").Died:Connect(function()
YourIntValueHere.Value = YourIntValueHere - 1
end)
end

very simple script and works if any player dies at any moment

Answer this question