Some Humanoid doesnt take damage

hi i want to make a skill that damages characters.

its half working some characters are affected some are not.

local rs = game:GetService(“ReplicatedStorage”)
local debris = game:GetService(“Debris”)
local s = rs.grounds

local remote = rs.spikes

remote.OnServerEvent:Connect(function(p)
local c = p.Character
local x = Instance.new(“Part”, workspace)
x.Size = Vector3.new(15,4,32)
x.CanCollide = false
x.Transparency = .2
x.Massless = true
local w = Instance.new(“Weld”,x)
w.Part0 = c.HumanoidRootPart
w.Part1 = x
w.C1 = CFrame.new(0,0,17)

	local spike = s:Clone()
	spike.Parent = workspace
	spike.Anchored = true
	spike.CanCollide = false
	spike.Massless = true
	spike.CFrame = x.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(180),0) * CFrame.new(-2,-6,0)
	
	

	for i, v in pairs(x:GetTouchingParts()) do
		if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= c and v.Parent:FindFirstChild("Hit"..p.Name) == nil then

			local x = Instance.new("IntValue", v.Parent)
			x.Name = "Hit"..p.Name
			game.Debris:AddItem(x, .1)

			v.Parent.Humanoid:TakeDamage(20)
		end
	end
	
debris:AddItem(x,.2)
debris:AddItem(spike,2)

end)

i looked up posts and the media but i didnt found anything relevant.

sorry this is my first post and the blockquote isnt really working.

Use :GetPartsInPart, because it’s more performant and more accurate.

Code:

local rs = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local s = rs.grounds

local remote = rs.spikes

remote.OnServerEvent:Connect(function(p)
	local c = p.Character
	
	local overlapParams = OverlapParams.new()
	overlapParams.FilterType = Enum.RaycastFilterType.Exclude
	overlapParams.FilterDescendantsInstances = {c}
	
	local x = Instance.new("Part")
	x.Size = Vector3.new(15,4,32)
	x.CanCollide = false
	x.Transparency = .2
	x.Massless = true
	x.Parent = workspace
	
	local w = Instance.new("Weld")
	w.Part0 = c.HumanoidRootPart
	w.Part1 = x
	w.C1 = CFrame.new(0,0,17)
	w.Parent = x

	local spike = s:Clone()
	spike.Anchored = true
	spike.CanCollide = false
	spike.Massless = true
	spike.CFrame = x.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(180),0) * CFrame.new(-2,-6,0)
	spike.Parent = workspace
	
	local charactersHit = {}

	for i, v in workspace:GetPartsInPart(x, overlapParams) do
		if v.Parent:FindFirstChild("Humanoid") and not charactersHit[v.Parent] then
			charactersHit[v.Parent] = true

			v.Parent.Humanoid:TakeDamage(20)
		end
	end

	debris:AddItem(x,.2)
	debris:AddItem(spike,2)
end)

thank you very much for the fast reply

1 Like

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