Gun doesn't work sometimes after getting killed by a player

NOTE: I could not recreate the actual bug, but it goes like this:

  • I equip the gun
  • I get killed by the other player
  • The gun won’t work after getting killed, but will work if I reset by myself*

(Maybe it’s because I’m using a Skinned Mesh character?)

I tried to disable the gun when the player dies, even deleting it. But this will only occur when the player is killed by another player. The error will say something about Health, specifically Health is not a valid member of Humanoid. The error will be present in the following script:
1.

runService.RenderStepped:Connect(function(dt)
	local char = game.Players.LocalPlayer.Character
	local hum = char:FindFirstChild("Humanoid")
	DynamicCrosshair:Update(dt)
	for i, v in pairs(player.Character:GetChildren()) do
		if v:IsA("Tool") then
			player.PlayerGui.HUD.Frame.Visible = true
			OTS_CAMERA_SYSTEM:Enable()
			DynamicCrosshair:Enable()
		else
			player.PlayerGui.HUD.Frame.Visible = false
			if OTS_CAMERA_SYSTEM.IsEnabled then
				OTS_CAMERA_SYSTEM:Disable()
			end
			DynamicCrosshair:Disable()
		end
	end
	if hum.Health <= 0 then
		hum:ChangeState(Enum.HumanoidStateType.Dead)
		if OTS_CAMERA_SYSTEM.IsEnabled then
			OTS_CAMERA_SYSTEM:Disable()
		end
		DynamicCrosshair:Disable()
	end
end)

game.ReplicatedStorage.DamageGiven.OnClientEvent:Connect(function()
	script.HitMarker:Play()
end)

But the thing is, after this error is shown, the gun will not work anymore, and I have to reset manually.

Can anybody help me? Thanks!

2 Likes

When you die and respawn, the script doesn’t detect you, I think.

change this line

local char = game.Players.LocalPlayer.Character

to this

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
1 Like

I’ll try this tommorow, as today I don’t have time, if it does work, the solution’s for you!

3 Likes

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