Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

PlayerDead/Alive function problems?

A day ago I asked a question saying 'How do I make a function so that if all players are dead or if 1 player is alive the round ends?' and some one help me come up with this:

[PLAYERDEAD/ALIVE FUNCTION]

local wordValue = game.ReplicatedStorage.valueStorage.wordValue
local timeValue = game.ReplicatedStorage.valueStorage.timeValue

function playersCurrentlyPlaying()  
    local playerDead = 0

    for loopTime, loopPlayers in ipairs (game.Players:GetChildren()) do
        if loopPlayers.playValue.Value == 0 then 
            playerDead = 1
        end
    end

    if playerDead == 0 then 
        print 'Players are alive!'
	elseif playerDead == 1 then
         wordValue = "All players have died!"
         timeValue = "0:00"
	end
end

[FUNCTION IT'S USED IN]

function roundCountdown()
	wordValue.Value = 'Time left!'
	
    for minuteTime = 2, 0, -1 do
        for secondsTime = 59, 0, -1 do
            timeValue.Value = string.format("%d:%.2d", minuteTime, secondsTime)
			playersCurrentlyPlaying()
            wait(1)
        end
    end
end

It won't work and I'm not a very experienced scripter, so please let me know how or why it is wrong and a way to fix it, thanks!

1 answer

Line 16/17, first script:

You are not setting the value object's Value. You are changing the variable's value instead.

Comparison:

local val = script.ExampleValue
val = "yey"
print(val,val.Value)

-- would error, since the variable is no longer an object value, it won't have any properties

local val = script.ExampleValue
val.Value = "i work properly!"
print(val," i work properly")

-- would print "ExampleValue i work properly"

Hopefully that made sense. If you need any more help, tell me in the comments.

~TDP

4 comments

0

It does work, but when one player dies the entire round ends. I wanted it so that if all players die or if 1 player is alive.

0

Also, when playerDead == 1 it doesn't with the rest of the function's. If you don't understand what I'm saying then I'll be happy to let you 'inspect' the code.

0

Ok. I'll be able to do it later today, PM my main account (EmeraldSlash)

0

Alright, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.