Why are players dying for no reason? (they're very mad at me!)

A lot of players in my game are getting very angry, they’re saying they keep dying for no reason.
I haven’t seen this bug with my own eyes yet, but on the group wall there’s hundreds of people complaining about it. That’s awful and causes so many players to leave and dislike. But I have no idea why it’s happening, this is the script:

-- the script uses Humanoid.Touched which is not great
-- but I don't think that's causing the issue now
game.Player.PlayerAdded:Connect(function(Player) --when a player joins
	local function StartCharacter(PlayerChar) --function to run when the character (re)spawns
		repeat wait(0.01) until PlayerChar:WaitForChild("Humanoid") --wait for humanoid
		local PlayerHum = PlayerChar.Humanoid
		PlayerHum.Touched:Connect(function(HitObject) --when the player touches something
			if HitObject.Name == "KillBrick" then
				PlayerChar.Humanoid.Health = 0
			end
			-- some other if statements, but none of them influence .Health
		end)
	end

	if Player.Character then --if the player character is already loaded
		StartCharacter(Player.Character)
	end
	Player.CharacterAdded:Connect(function(PlayerChar) --if the player respawns
		StartCharacter(PlayerChar)
	end)
end)

The killbricks are far enough from the checkpoints so the issue must be something with the code being executed too late or something. I’m really clueless about what’s going on.
Does anyone know what’s wrong? Thanks in advance.

2 Likes

The humanoid doesnt have a hitbox, which means nothing can collide with it. I think if you switched humanoid with humanoidrootpart, it would stop.

local PlayerHum = PlayerChar.HumanoidRootPart
PlayerHum.Touched:Connect(function(HitObject) --when the player touches something
	if HitObject.Name == "KillBrick" then
		PlayerChar.Humanoid.Health = 0
	end
	-- some other if statements, but none of them influence .Health
end)

Also, the repeat wait(0.01) until isnt needed. It can be made into:

PlayerChar:WaitForChild("Humanoid")
2 Likes

Adding onto what @Axominock said, not only should you check for the HumanoidRootPart hitting a killbrick (how would the HumanoidRootPart hit a killbrick on the ground), you should actually see if you can just loop through all of the player’s character’s parts to see if any of them hit the killbrick.

1 Like

@Axominock and @1Urge thanks for your replies.
Humanoid.Touched actually does work, and it already works for all parts in the player (so even if they hit a killbrick on the ground). It’s not the best technique though, so I will change that later on, but the bug is not because of that I think.

This is indeed true, I will change it.

Humanoid events are known to be super buggy and unreliable, which is why a lot of developers don’t even use them, so actually your humanoid event may have something to do with it, considering how buggy they can be.

And actually, if that doesn’t work, then I would flip it around and check for whenever the Killbrick part is touched, not the humanoid, because if you think about it, the humanoid is walking around and touching so many things, which could create some performance issues when there are a lot of people in one game, and you have all these touched events firing while everyone is walking around.

The killbrick on the other hand is stationary and does not move, so you could check for whenever the Killbrick is touched, simply by doing:

if hit.Parent:FindFirstChild(“Humanoid”) then
—it is a player so kill them
end

Sorry for the bad formatting I’m on my phone.

By checking the killbrick instead, you will be saving so much performance.

2 Likes

Instead of checking Humanoid.Touched (which will fire a lot), listen to KillBrick.Touched instead. I recommend using CollectionService or a folder to gain easy access to all your killbricks, and then connect their .Touched events to a function that kills any player that touches them.

For performance reasons, ensure you are not creating a new function for every killbrick. You can do this by creating the function and assigning it to a variable, then instead of Connect(function() (which creates a new function) you can do Connect(functionVariable).

2 Likes
game.Players.PlayerAdded:Connect(function(Player)
    local function StartCharacter(Player)
         local KillPart = game.Workspace. -- Add your killpart name there.

        KillPart.Touched:Connect(function(hit)
             if not hit.Parent.Parent:IsA("Player") then return end
                hit.Parent:FindFirstChild("Humanoid").Health = 0
            end
        end)
        if Player.Character then
           StarteCharacter(Player)
        end
        Player.CharacterAdded:Connect(function(Character)
            StartCharacter(Player)
        end)
    end
end)

Let me know if it doesn’t work!

1 Like

wouldn’t you want to refer to the killpart as script.Parent?

It most likely is not the script’s parent, but you could if it was. I’d just want to make sure the location is correct!

It normally would be because it’s more convenient if you have multiple for it to be the script’s parent

What Rig types are you using?

If R15 or custom then you may want to change the Humanoid HitBox from Outer to Inner.

Usually you can touch objects that are like 1 stud away from your character because of that.

Go to game settings > Avatar > Collision > Inner.

I’m not 100% sure its your issue but it’s worth a shot.
(Also to add. Have you play tested your own gme?)

Thanks for your reply! I’m using rig type R6 so unfortunately I don’t think that’s what it is. I’ll still check it out though.
EDIT: It’s set to outter, but does this still matter with rig type R6?

And yes I have play tested the game a thousand times already, and never had the bug happen to me. The only thing I notice is that there can be a quite long delay from when the player touches a killbrick until they actually die.

1 Like

Did you even attempt the 3-4 solutions given before the r15 one? The delay is most likely from your humanoid touch event running 49 times a second. Somebody even rewrote your code for you. Test our solutions before writing back about how nothing is solved.

If you have tested our other solutions, then I apologise, however you should’ve specified that instead of ignoring them all I your reply post, and told us which ones you’ve tried, and which ones you haven’t.

1 Like

I’m really sorry that I have not replied to those solutions yet. I first am trying them all out ASAP.
And I already updated the game to use KillPart.Touched instead of doing it via the Humanoid. But before I can tell if it’s working I need to wait if players stop reporting the bug.

The post I already replied to, are just the few things that I can already answer.

Do you recommend that I just mark a reply temporally as the solution? So that this thread doesn’t stay on top of the scripting-support?

No don’t mark anything as a solution if it doesn’t work. Another reason you might not be able to reproduce the bug is if you are testing on your own. If you do this, there might not be as much traffic as there would be in a server with 8-10 people.

Sorry for sounding harsh.

1 Like

Thank you so much! I updated the game to that code and published it. Now I’m just waiting to see if players will stop reporting the bug. But since roblox is having some troubles at the moment that might still take a while. I’ll let you know as soon as I can, thanks again :))

Okay then I’ll do it as soon as I know more.

Yeah that might be true, but I’ve also playtested a lot of times in servers with 30 players, the delay is indeed longer, but the “dying all the time” never happens to me.

And don’t worry, you were right. I should’ve replied to more people indeed. I’ll try to avoid it in the future.

1 Like

One thing that might help is if you go into a busy server and ask if anyone is having this issue, and if they are you should go over and see what it looks like/what might be causing it.

2 Likes

Ohh that’s smart, I will try it out if the bug reports keep coming. Thanks :))

1 Like