I keep dying randomly while normally playing the game

You can write your topic however you want, but you need to answer these questions:

  1. What is the issue? I keep dying randomly for no reason and also this happens to other people

  2. What solutions have you tried so far? I did look over everything in the dev forum no luck though.

game.Players.PlayerAdded:Connect(function(plr)

	for _, v in game.Workspace.ExampleFolder:GetChildren() do 
		if v:IsA("Part") then
			v.Touched:Connect(function()
				if plr.Team == game.Teams.Example2 then
					plr.Character.Humanoid.Health = 0 
					
				end
			end)
		end
	end
end)

And also, Yes my team was not example2 and I did not touch the part.

This works just fine for me (improved your script):

for _, v in workspace:WaitForChild("ExampleFolder"):GetChildren() do 
	if not v:IsA("Part") then continue end
	
	v.Touched:Connect(function(hit)
		local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

		if plr and plr.Team == game:GetService("Teams").Example2 then
			plr.Character.Humanoid.Health = 0 
		end
	end)
end

If this doesn’t work for you then another script must be killing your player constantly.

1 Like

I never knew “GetPlayerFromCharacter” Existed I think the issue was from the playeradded event, Anyways thanks this worked perfectly.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.