I'm trying to make my hit boxes cancollide property to false upon death. They don't seem to be doing so

Hey! im making some hitboxes for my shooter game. They are supposed to collide with the world. I want that collision to disappear when the player dies. The event for Died doesn’t appear to be firing. Here is the script for the collisions:

script.Parent.Died:Connect(function()
	print ("the player has died")
	local hitbox = script.Parent.Parent.hitbox
	hitbox.BrickColor = "Navy Blue"
	hitbox.CanCollide = false
	wait(5)
	hitbox.CanCollide = true
end)

the part is supposed to lose collisions and turn navy blue when the character dies.

this script is inside “Humanoid” inside startercharacter.

the print inside the function isn’t printing, so the function isn’t firing. Any help?

1 Like

Hey try this:

game:GetService("Players").LocalPlayer.Character.Humanoid.Died:Connect(function()
	print ("the player has died")
	local hitbox = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart
	hitbox.BrickColor = "Navy Blue"
	hitbox.CanCollide = false
	wait(5)
	hitbox.CanCollide = true
end)

Put this in anything that replicates to the client.

I tested this script out on a local script, doesn’t appear to work.
Did some digging and found out you can do this by the server.

game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
	character:WaitForChild("Humanoid").Died:Connect(function()
		local hitbox = character.HumanoidRootPart
		hitbox.BrickColor = BrickColor.new("Navy blue")
		hitbox.CanCollide = false
	end)
end)

end)

You dont need to set CanCollide back to true cause it automatically should on respawn.

1 Like

I added a print into the function to make sure it was firing. The Died event still isnt firing when I use your script.

Make sure it’s a server script in serverScriptService

thanks for the amendment! it worked

1 Like