I’m trying to create a script that can detect when a user dies in a round and then later remember that the user died in a server script.
I have a working script that can detect when a user died in a for loop but I do not know how to carry this data outside of that loop and use it later.
I’ve scowered the forum so far but I could not find any individual post that worked for what I was trying to do. I have tried a LocalScript that can detect when the user dies and changes a BoolValue to true or false but the player is reset when it dies so the BoolValue would never change to true when the player died. I also don’t want to rely on the client for information due to explotiers. What I think will work is checking when the player dies in the for loop and then outside of that for loop using that information again to see if the player died during a round.
Previously mentioned snippet of server script:
for timeleft = 30, 0, -1 do
for i,v in pairs(Players:GetChildren()) do
if v.PlayerGui:FindFirstChild("ScreenGui") ~= nil then
v.PlayerGui.ScreenGui.Broadcast.Text = "Round Time Left: " .. timeleft
if v.Character.Humanoid.Health == 0 then
print("Player died.")
-- This is where I am having trouble. How do I carry this information over to when the round ends?
end
end
end
wait(1)
end
-- Check for plr death
for i,v in pairs(Players:GetChildren()) do
print(v.Name)
if v.PlayerGui:FindFirstChild("ScreenGui") ~= nil --[[insert check if player died during round here]] then
v.PlayerGui.ScreenGui.SmallText.Text = "You survived!"
else
v.PlayerGui.ScreenGui.SmallText.Text = "You died. :("
end
v = true
end
In short, how do I carry a value outside of a for loop and save it for an individual player in a server script? Also, is there a better way to go about this?