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

Script checks if player is on red team then gives the player one point (check more text . -?)

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)`

2 comments

0

Can you be a bit more clear? What exactly are you trying to do?

0

I edited post BoiBoi24T

2 answers

✓ Accepted answer

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)

14 comments

0

@T3_MasterGamer it gives me an error at: 'task.spawn(redTeamScored, true)' and 'task.spawn(redTeamScored, true)' it puts a red line under both redTeamScored

0

It gives me the error: Workspace.BlueSide.Void.BlueScript:32: invalid argument #1 to 'spawn' (function or thread expected)

0

Oh sorry! I fixed it.

0

It still does not work but it does not give me an error this time. Do i have to put the Frame somewhere besides starterGui?

0

Is the script a normal scritp and inside ServerScriptService?

0

Nevermind I fixed it, But I have one last thing to ask you. So I have a Respawning Gui that comes up when you die and tells you how many secs till respawn. So my question is, How do I make it so when the player scores it shows the redTeamScored Gui but not the respawning Gui.(respawning gui: game.StarterGui.DeathGui)

0

Do you have a script that popups the DeathGui?

0

Yes

0

Show me.

0

Check Answers place

0

Done! Please accept my answer if it works. :)

0

It does not work, it does not give me any errors for this script but it gives me an error in the script thats in DeathGui. This is the error: Players.PreviousSchmuck.PlayerGui.DeathGui.LocalScript:10: attempt to index nil with 'Value'

0

Change line 10 of the local script in deathgui to if killer and killer.Value then you should always check if the creator tag exists, if not it will error if player resets on themself.

0

It does not work, Now it just shows the DeathGui and the redTeamScored Gui does not show.

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)

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