Players and Dummies not taking damage

I have a script that detect’s when its touched and then will deal damage if it has a humanoid, but its not dealing damage and not even detecting that it touched.

Script:

local debounce = false
local damage = 20
game.Players.PlayerAdded:Connect(function(plr)
	
	script.Parent.Touched:Connect(function(hit)
		print('works')
		if hit.Parent:FindFirstChild('Humanoid') and debounce == false and hit.Parent.Name ~= plr.Name then
			print('works AGAIN')
			debounce = true
			hit.Parent.Humanoid.Health -= damage
			print('works perfectly')
			task.wait(5)
			debounce = false
		end
	end)
end)

You don’t need the PlayerAdded function.

New code:

--//Variables
local Part = script.Parent

--//Controls
local Damage = 20

--//Tables
local DamageDebounces = {}

--//Functions
Part.Touched:Connect(function(hit)	
	local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	
	if not Humanoid or DamageDebounces[Humanoid] then
		return
	end
	
	DamageDebounces[Humanoid] = true
	
	Humanoid.Health -= Damage
	
	task.wait(5)
	DamageDebounces[Humanoid] = nil
end)

It works but, it damages the player who summoned it aswell, is there a way to make it so it doesnt damage the player who used it?

What’s the script you use for summoning the thing?

Here is the script that summons it:

game.ReplicatedStorage.Remotes.MousepOSITION.OnServerEvent:Connect(function(player, mousep)
	local tweenservice = game:GetService('TweenService')
	local clone = game.ReplicatedStorage.IceCube:Clone()
	local char = player.Character
	clone.CFrame = char.LowerTorso.CFrame
	clone.Position = Vector3.new(clone.Position.X, 40, clone.Position.Z)
		clone.Parent = char
		print('oh yeah')
	local tweeninfo = TweenInfo.new(
		1,	
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tween = tweenservice:Create(clone, tweeninfo, {Position = mousep.Position})
		tween:Play()
		player.stats.Stamina.Value = player.stats.Stamina.Value - 15
		print('tween played')
		

		tween.Completed:Wait()
		print('tween completed')
	local hitboxclone = game.ReplicatedStorage.HitBox:Clone()
	hitboxclone.Parent = clone
	hitboxclone.Position =  clone.Position
	local explosion = Instance.new('Explosion')
	explosion.Parent = clone
	explosion.BlastRadius = '10'
	local smoke = game.ReplicatedStorage.Ice:Clone()
		smoke.Parent = clone
		clone:Destroy()
		print('destroyed')

	
end)


What’s the part that damages the player?

Here it is, the script that damages it is in it.

Change your script to this:

local tweenservice = game:GetService('TweenService')

local tweeninfo = TweenInfo.new(
	1,	
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

game.ReplicatedStorage.Remotes.MousepOSITION.OnServerEvent:Connect(function(player, mousep)
	local char = player.Character

	if not char or not mousep then
		return
	end
		
	local clone = game.ReplicatedStorage.IceCube:Clone()
	clone.CFrame = char.LowerTorso.CFrame
	clone.Position = Vector3.new(clone.Position.X, 40, clone.Position.Z)
	clone:SetAttribute("Owner", player.UserId)
	clone.Parent = char
	print('oh yeah')

	local tween = tweenservice:Create(clone, tweeninfo, {Position = mousep.Position})
	tween:Play()
	player.stats.Stamina.Value -= 15
	print('tween played')

	tween.Completed:Wait()
	print('tween completed')
	
	local hitboxclone = game.ReplicatedStorage.HitBox:Clone()
	hitboxclone.Position =  clone.Position
	hitboxclone.Parent = clone
	
	local explosion = Instance.new('Explosion')
	explosion.BlastRadius = 10
	explosion.Parent = clone

	local smoke = game.ReplicatedStorage.Ice:Clone()
	smoke.Parent = clone
	
	clone:Destroy()
	print('destroyed')
end)

And your other script to this:

--//Services
local Players = game:GetService("Players")

--//Variables
local Part = script.Parent

--//Controls
local Damage = 20

--//Tables
local DamageDebounces = {}

--//Functions
Part.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	
	if Player and Part:GetAttribute("Owner") == Player.UserId then
		return
	end
	
	local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")

	if not Humanoid or DamageDebounces[Humanoid] then
		return
	end
	
	DamageDebounces[Humanoid] = true

	Humanoid.Health -= Damage

	task.wait(5)
	DamageDebounces[Humanoid] = nil
end)

It works, put the part is shaking alot. Can collide is off aswell.

Video:
robloxapp-20221011-1551513.wmv (872.6 KB)

Is CanTouch turned on in the part?

Yes, I just checked and it is on

1 Like

Is the part anchored?

Add a string value into the tool handle/hitbox and name it “who” or something
then in the summoning script, change the who value to the player name
In the hit script, detect if the person hit is the who value, and if true then ignore that hit.
Hope I’m not confusing lol

game.ReplicatedStorage.Remotes.MousepOSITION.OnServerEvent:Connect(function(player, mousep)
	local tweenservice = game:GetService('TweenService')
	local clone = game.ReplicatedStorage.IceCube:Clone()
	local char = player.Character
	clone.CFrame = char.LowerTorso.CFrame
	clone.Position = Vector3.new(clone.Position.X, 40, clone.Position.Z)
		clone.Parent = char
		print('oh yeah')
	local tweeninfo = TweenInfo.new(
		1,	
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tween = tweenservice:Create(clone, tweeninfo, {Position = mousep.Position})
		tween:Play()
		player.stats.Stamina.Value = player.stats.Stamina.Value - 15
		print('tween played')
		

		tween.Completed:Wait()
		print('tween completed')
	local hitboxclone = game.ReplicatedStorage.HitBox:Clone()
--hitboxclone.String_Name_Here.Value = player.Name 
	hitboxclone.Parent = clone
	hitboxclone.Position =  clone.Position
	local explosion = Instance.new('Explosion')
	explosion.Parent = clone
	explosion.BlastRadius = '10'
	local smoke = game.ReplicatedStorage.Ice:Clone()
		smoke.Parent = clone
		clone:Destroy()
		print('destroyed')

	
end)

It already works for him, and you should be using attributes for this like I did. The only problem he has is with the animation.

Part.Touched:Connect(function(hit)	
	local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
--if hit.Parent.Name == String_Name_Here.Value then

Alright, I’m guessing it’s in the video file which I cannot view.