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)