Bullet hit detection system

character script

local IsDamaged = false -- [ You can also implement variables to set which Body Part is damaged.
function test()
	if script.Parent:FindFirstChild('IsPlayerHit') and not (IsDamaged == true) then -- [ debounce
		IsDamaged = true
		print("hit")
	end
end

while wait() do
	test()
end

bullet script

local bullet = script.Parent

function tag(char)
	local tag = Instance.new('IntValue',char)
	tag.Name = 'IsPlayerHit'
end

local TaggedPlayers = {}

bullet.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not table.find(TaggedPlayers,hit.Parent.Name) and not (hit.Parent:FindFirstChild('IsPlayerHit')) then
		tag(hit.Parent)
		table.insert(TaggedPlayers,hit.Parent.Name)
	end
end)

try changing them now.

I noticed something btw, Whenever I run this script on the server the module script where the bullet is made doesn’t show on server but shows when its an Instance.new

	local laserPart = game.ReplicatedStorage.Bullet
	local clonedbullet = laserPart:Clone()
	clonedbullet.Parent = workspace
	clonedbullet.Size = Vector3.new(0.2,0.2,laserDistance)
	clonedbullet.CFrame = laserCFrame

	-- Add laser beam to the Debris service to be removed & cleaned up
	game.Debris:AddItem(clonedbullet, SHOT_DURATION)

wait never mind, just do the changes of the scripts

1 Like

Just did, I still see no changes. I don’t see a tag or anything

what about the bullet script? did it do changes?

local bullet = script.Parent

function tag(char)
	local tag = Instance.new('IntValue',char)
	tag.Name = 'IsPlayerHit'
end

local TaggedPlayers = {}

bullet.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not (table.find(TaggedPlayers,hit.Parent.Name)) and not (hit.Parent:FindFirstChild('IsPlayerHit')) then
		tag(hit.Parent)
		table.insert(TaggedPlayers,hit.Parent.Name)
	end
end)

i forgot to put parenthesis lol wait heres the new one

1 Like

Nope, still doesn’t work. I think I’ll have to use the instance.new for it to work.,

I still dont know whats going on, and I need to go sorry. By the way, you should try debounce, its a useful variable that you can use to stop spamming.
Try seeing this for a little help!

1 Like