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

I want to make it so my deathGui doesnt show up when you score. How? (check bottom for more info)

this script checks if a player is on red team when they touch a block then if that person is, the person gets one point. Then once that happens it makes a frame show up and kills all players. But I have a Gui that pops up when you die, I would like to make it so when it kills you after you score. The DeathGui doesnt show up. i tried to do that with this : player:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = not visible. But it does not work, Can anybody tell me why this is happening thank you. (By the way the code is on line 20)

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local function killEveryPlayer()
    for _, player in ipairs(Players:GetPlayers()) do
        task.spawn(function()
            local character = player.Character
            if (not character) or (not character.Parent) then
                character = player.CharacterAdded:Wait()
            end
            character:FindFirstChildOfClass("Humanoid").Health = 0
        end)
    end
end

local function redTeamScoredFrame(visible: boolean)
    for _, player in ipairs(Players:GetPlayers()) do
        task.spawn(function()
            player:WaitForChild("PlayerGui"):WaitForChild("RedTeamScored"):WaitForChild("Frame").Visible = visible
            player:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = not visible
        end)
    end
end

local debounce = false
script.Parent.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model"))
    if (player and player.Team.Name == "Red Team") and (debounce == false) then
        debounce = true
        player.leaderstats.Points.Value += 1

        task.spawn(killEveryPlayer)
        task.spawn(redTeamScoredFrame, true) -- makes RedTeamScore Frame visible

        task.wait(3)
        task.spawn(redTeamScoredFrame, false) -- makes RedTeamScore Frame invisible
        debounce = false
    end
end)

1 answer

✓ Accepted answer

Okay I fixed my answer. Put line 20 after line 11 or just paste this code:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local function killEveryPlayer()
for _, player in ipairs(Players:GetPlayers()) do
		task.spawn(function()
			local character = player.Character
			if (not character) or (not character.Parent) then
				character = player.CharacterAdded:Wait()
			end
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			humanoid.Health = 0
			humanoid.Died:Wait()
			player:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = false
			task.wait(2.5)
			player:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = true
		end)
	end
end

local function redTeamScoredFrame(visible: boolean)
    for _, player in ipairs(Players:GetPlayers()) do
        task.spawn(function()
		player:WaitForChild("PlayerGui"):WaitForChild("RedTeamScored"):WaitForChild("Frame").Visible = visible
		end)
	end
end

local debounce = false
script.Parent.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model"))
	if (player and player.Team.Name == "Red Team") and (debounce == false) then
		debounce = true
		player.leaderstats.Points.Value += 1
		
		task.spawn(killEveryPlayer)
		task.spawn(redTeamScoredFrame, true) -- makes RedTeamScore Frame visible
		
		task.wait(3)
		task.spawn(redTeamScoredFrame, false) -- makes RedTeamScore Frame invisible
		debounce = false
	end
end)

6 comments

0

Does not work. It puts a red line under visible next to not (Line 12)

0

Oh right, sorry -_-‘

0

I fixed it for the last time.

0

it works but it comes back up to early can you make it come back after like 2.5 seconds more?

0

done

0

Thank You! I accepted your answer.

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