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

Check if a player died. And credit a team for it? [UPDATE]

I have a script that when a player dies it adds a value to the score board. This is a shooter game and when the player dies I found that if you continue to shoot the body until it disappears it will keep adding points.

Heres the script, I hope someone can help me out. I know it cant be too complicated, I may be over thinking it.

for i, v in pairs(game.Teams["Green Team"]:GetPlayers()) do
	v.Character:WaitForChild("Humanoid").Died:connect(function()
		RTkills.Value = RTkills.Value + 1
	end)
end

So I figured id add more of the script, because I have a feeling people may need it

So here is the whole chunk of code that this is in.

	-- Starts round and also gets players from teams
	for i = GameTime, 0, -1 do
		status.Value = i.." Time Left!"
			-- Gets Green Team and checks to see if player died, if so give red team a point
			for i, v in pairs(game.Teams["Green Team"]:GetPlayers()) do
				v.Character:WaitForChild("Humanoid").Died:connect(function()
					RTkills.Value = RTkills.Value + 1
				end)
			end
			-- Gets Red Team and checks to see if player died, if so give Green team a point
			for i, v in pairs(game.Teams["Red Team"]:GetPlayers()) do
				
			end
		if i == 0 then
			
			-- Rounds over
			status.Value = "Round Over!"
			wait(RoundOver)
			
			-- Give players points
			for _, player in pairs(game.Players:GetPlayers()) do
				if player:FindFirstChild("leaderstats") then
					player.leaderstats.Presents.Value = player.leaderstats.Presents.Value + 5

				end
			end
			break
		else
		end
		wait(1)
	end

Its in a team script because its a shooter and so when someone on that team dies it adds a point. But again its triggering more than once.

Thank you for your time :)

3 comments

0

how many times

0

Its different everytime. I think it may be my gun script.

0

Nope its not my gun script. Because even when you reset your character it still runs multiple times

2 answers

✓ Accepted answer
game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		char:WaitForChild("Humanoid").Died:connect(function()
			if plr.Team.Name == "Green Team" then
				RTkills.Value = RTkills.Value + 1
			else
				GTkills.Value = GTkills.Value + 1
			end
		end)
	end)
end)
for i = GameTime, 0, -1 do
	status.Value = i.." Time Left!"
	wait(1)
end
status.Value = "Round Over!"
wait(RoundOver)
for i,v in pairs(game.Players:GetPlayers()) do
	v.leaderstats.Presents.Value = v.leaderstats.Presents.Value + 5
end

replace your old code by this much more efficient one and not crappily indented it does the exact same thing

1 comment

0

It doesnt work Im afraid. Good try thought.

IF you keep shooting the Humanoid. I suggest you have a value if the player is dead or not, and check that before rewarding the kill.

2 comments

0

Bro thats what the died function does. It checks if the player is dead.

0

Your an idiot.. Set the value to true if the player is dead and set it to false once respawned. Check that with the dead event. If you don't understand that seriously just go away.

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