How do I make it so after gives 1 point it makes a frame visible then kills all players in the server then makes frame not visible. I am trying to make it so when a player scores a point when he touches the part if makes a frame visible( game.StarterGui.RedTeamScored.Frame) then after like 1 second it kills all players and makes the frame not visible.
`local Players = game:GetService("Players") local Teams = game:GetService("Teams") local debounce = false script.Parent.Touched:Connect(function(hit) local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) if player and player.Team == Teams["Red Team"] then if debounce then return end debounce = true player.leaderstats.Points.Value += 1 task.wait(3) debounce = false end end)`
Instead of using the StarterGui
to make the frame visible, you should use the PlayerGui
inside the Player
, since everything inside StarterGui
will replicate inside Player.PlayerGui
when the player joins. Another reason is that if you tried to edit it in StarterGui
, it won't affect PlayerGui
, and StarterGui
is only accessible in the client (LocalScripts).
To kill every player in the server, you can get an array of all players in the server using Players:GetPlayers()
and iterate through the array using either pairs()
or ipairs()
. ipairs()
is recommended for arrays because it is faster. To kill the player, you can use either Player:LoadCharacter()
or Player.Character:FindFirstChildOfClass("Humanoid").Health = 0
. The difference between the two is their RespawnTime. Player:LoadCharacter()
respawns the player immediately, while Player.Character:FindFirstChildOfClass("Humanoid").Health = 0
respawns after 3 seconds (default).
Final Script:
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)
to T3_MasterGamer's comment:
This first script is in the DeathGui:
local cam = workspace.CurrentCamera local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() local char = plr.Character or plr.CharacterAdded:Wait() local hum = char:WaitForChild("Humanoid") local imalabel = script.Parent.Frame.ImageLabel local texlabel = script.Parent.Frame.TextLabel hum.Died:Connect(function(killed) local killer = char.Humanoid:FindFirstChild("creator") if killer.Value then local killerChar = killer.Value.Character local killerName = killer.Value.Name local killerId = killer.Value.UserId local image, isReady = game.Players:GetUserThumbnailAsync(killerId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size180x180) cam.CameraSubject = killerChar.Humanoid script.Parent.Frame.Visible = true imalabel.Image = image texlabel.Text = killerName wait(10) cam.CameraSubject = hum script.Parent.Frame.Visible = false end end)
This script is in ServerScriptService:
local players = game.Players local t = 5 players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") humanoid.Died:Connect(function(died) player.PlayerGui:FindFirstChild("DeathGui"):WaitForChild("Frame").Visible = true for i = t,0,-1 do player.PlayerGui:FindFirstChild("DeathGui").Frame.Timer.Text = "Respawning in"..i wait(1) end player.PlayerGui:FindFirstChild("DeathGui"):WaitForChild("Frame").Visible = false end) end) end)