Fists Tool Damage error and RayCasting ReOpen

Hello guys, So this is a reopening of yesterday’s topic because I have something else to discuss. So I am making a fists tool, but I have a problem with the abilities I am making. When you press “Z” while equipping the tool, it should play a smashing animation, And ray-casts the ground, and deals damage to the enemy. But the problem is that the hitbox (the handle) range is the player’s hand. I want the range to be on the circle so anyone inside of the circle (except the player that’s activated it) will be damaged, also when clicking the Z and not touching the enemy, it will stay enabled until I touch the enemy to deal the damage. and I get this error

Players.Koki0991.Backpack.Fists.Idle.Damage:62: table index is nil

Watch This Video:

here are the scripts:

Local Script:

local tool = script.Parent

local uis = game:GetService("UserInputService")
local DamageEvent = game:GetService("ReplicatedStorage").DE
local CastEvent = game:GetService("ReplicatedStorage").CE
local canUse = false
local cooldown
local anim = Instance.new("Animation")
anim.Parent = script
anim.Name = "Idle"
anim.AnimationId = "rbxassetid://13176553664" 

local anim2 = Instance.new("Animation")
anim2.Parent = script
anim2.Name = "Smack"
anim2.AnimationId = "rbxassetid://13186940517" 

local track
local track2

tool.Equipped:Connect(function()
	print("Can Use")
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track2 = script.Parent.Parent.Humanoid:LoadAnimation(anim2)
	track.Priority = Enum.AnimationPriority.Action
	track.Looped = true
	track2.Looped = false
	game.Players.LocalPlayer.PlayerGui.Abilities.Fists.Visible = true
	canUse = true
	track:Play()
end)

tool.Unequipped:Connect(function()
	print("Can't Use")
	if track then
		track:Stop()
		game.Players.LocalPlayer.PlayerGui.Abilities.Fists.Visible = false
		canUse = false
	end
end)


--------------------Z and X clicked script--------------------

uis.InputBegan:connect(function(input, Processed)
	if canUse == true then
		if not Processed then
			if input.KeyCode == Enum.KeyCode.Z then
				track2:Play()
				wait(0.2)
				game.SoundService.Smash:Play()
				DamageEvent:FireServer()
				CastEvent:FireServer()
				print("Z has been pressed")
			elseif input.KeyCode == Enum.KeyCode.X then
				print("X has been pressed")
			else
			end
		end
	end
end)

Server Script:

local tool = script.Parent.Parent

local handle = tool:WaitForChild("Handle").HitPart
local DamageEvent = game:GetService("ReplicatedStorage").DE
local CastEvent = game:GetService("ReplicatedStorage").CE
local TweenService = game:GetService("TweenService")
local PlayersHit = {}



--------------------Makes The RayCast--------------------

function RayCastEffect(HRP)
	local RayParams = RaycastParams.new()
	RayParams.FilterDescendantsInstances = {workspace.DebrisFolder}
	RayParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local Angle = 0
	
	for i = 1,30 do
		local Size = math.random(2,3)
		local Part = Instance.new("Part")
		Part.Anchored = true
		Part.Size = Vector3.new(1,1,1)
		Part.CFrame = HRP.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(Angle),0) * CFrame.new(10,5,0)
		
		game.Debris:AddItem(Part,5)
		
		local RayCast = workspace:Raycast(Part.CFrame.p,Part.CFrame.UpVector *- 10, RayParams)
		
		if RayCast then
			Part.Position = RayCast.Position + Vector3.new(0,-5,0)
			Part.Material = RayCast.Instance.Material
			Part.CanCollide = false
			Part.CanQuery = false
			Part.Color = RayCast.Instance.Color
			Part.Size = Vector3.new(Size,Size,Size)
			Part.Orientation = Vector3.new(math.random(-180,180),math.random(-180,180),math.random(-180,180))
			Part.Parent = workspace.DebrisFolder
			
			local Tween = TweenService:Create(Part,TweenInfo.new(.25,Enum.EasingStyle.Bounce,Enum.EasingDirection.InOut),{Position = Part.Position + Vector3.new(0,5,0)}):Play()
			delay(1,function()
				local Tween = TweenService:Create(Part,TweenInfo.new(1),{Transparency = 1,Position = Part.Position + Vector3.new(0,-5,0)}):Play()
			end)
		end
		Angle += 25
	end
end



--------------------When Z Clicked--------------------

DamageEvent.OnServerEvent:Connect(function(Player)
	local connection
	connection = handle.Touched:Connect(function(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= tool.Parent then
			if PlayersHit[Hit.Parent] == nil then
				Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
				PlayersHit[Hit.Parent] = true
				task.wait(1)
				PlayersHit[Hit.Parent] = nil
				connection:Disconnect()
			end
		end
	end)
end)




--------------------When Z Clicked But Plays The Raycast--------------------

CastEvent.OnServerEvent:Connect(function(Player)
	local Char = Player.Character
	local HRP = Char.HumanoidRootPart
	RayCastEffect(HRP)
end)

From what I understand, the script waits until a character is touched to disconnect the touch of the player’s hand from the function, so, after connecting the function called “connection” you get after the end of the function it’s connected to and wait a bit until disconnecting it automatically. It was probably unclear here’s what I meant:

local connection
	connection = handle.Touched:Connect(function(Hit)
		--the function
	end)
        task.wait()--put the time desired here
        connection:Disconnect()

I’ll try getting a solution to your “deal damage when the player is near the player who attacked” problem. Right now my best solution for it is to create a ball in the workspace that when touched, deals damage.

it does not damage the enemy at all

DamageEvent.OnServerEvent:Connect(function(Player)
	local connection
	connection = handle.Touched:Connect(function(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= tool.Parent then
			Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
			connection:Disconnect()
			print("Enemy Has Lost 25")
		end
	end)
	task.wait()
	connection:Disconnect()
end)

You’re not waiting at all I think, put a number like 1 in it

OMG Works Finally, I tried so much in the discord, on YouTube, and on this website everywhere.

Yeah thanks, but wait until you get an error that only shows 8 results on google to say that. Anyways, did you look for a way to detect when the player is in the range of the smash ground attack?

No, still I can’t find any assistance; someone says to use GetPartBoundsInRadius
but I don’t know how to make it work. I want the full line code. Could you help Please?

I want to detect everyone inside the range instead of detecting the player that’s touched the hitbox (handle).

Tell me if you want me to send you the code.

So, my idea was to detect when the player touches the z key (done) and send remote to the server when the animation for it is done. Now create a part with a ball shape, with the position of the player who attacked with CanCollide to false, transparency to 1 and others. On this forum I’ve seen someone use a function called :GetPartsInPart(), I looked up the function and it exists, try taking a look at it, but anyways once you’ve managed to get the parts in the ball, check if there’s a humanoid in the part’s parent if yes check if the character is the player who attacked getting help from the player parameter that comes up in the :FireServer() function if no then make the humanoid take damage.

Sorry, the forum doesn’t want us to ask for entire scripts :frowning:

Thanks for your help, and I’m sorry to bother you anyway. I’ll try your solution, but I actually need some other help (if you can). Do you want me to create another forum?

You can if you want, I like to get solutions on this forum anyways so I don’t mind

Again, thank you for your help.

Here:

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