-
What do you want to achieve?
A working ability that makes an impact on the ground. -
What is the issue?
The issue is that when I try to test my ability in a local server, I can’t hit another player sometimes but not all the time. -
What solutions have you tried so far?
I’ve tried readjusting the scope of my script, organizing it, and returning but everything i’ve tried hasn’t felt right. I don’t know the source of this issue because it’s somewhat spontaneous and random.
Video:
Server script:
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local StompAnim = SS.Animations.Stomp
local impact = RS.ImpactModel
local debouncetable = {}--USE THE DEBOUNCETABLE TECHNIQUE
local dummytable = {}
local hittable = {}
local function spawnimpact(rightleg, humanoid, char, plr)
local newplr
local function touchhitbox(hit) --Damaging
newplr = Players:GetPlayerFromCharacter(hit.Parent)
if newplr and not hittable[newplr] and newplr.Character ~= plr.Character then
print(hit.Parent)
hittable[newplr] = newplr
hit.Parent.Humanoid:TakeDamage(25)
elseif not newplr and not dummytable[hit.Parent] then
dummytable[hit.Parent] = hit.Parent
hit.Parent.Humanoid:TakeDamage(25)
dummytable[hit.Parent] = nil
end
end
local animtrack = humanoid:LoadAnimation(StompAnim)
local newimpact = impact:Clone()
local pos = newimpact.PrimaryPart
local raycast = workspace:Raycast(rightleg.Position,rightleg.CFrame.UpVector * -10) --Raycast material
if humanoid:GetState() == Enum.HumanoidStateType.Running or humanoid:GetState() == Enum.HumanoidStateType.Landed then --Check if not jumping or freefall
if plr and not debouncetable[plr] then --Check if player is not already in cooldown
debouncetable[plr] = plr --put in cooldown
animtrack:Play() -- play anim
newimpact.Hitbox.Quake:Play() -- play sound
animtrack.Stopped:Connect(function()
if raycast then
for i,v in pairs(newimpact:GetChildren()) do
v.BrickColor = raycast.Instance.BrickColor
v.Material = raycast.Material
end
newimpact.Area.SmokeEffect:Emit(30) --Emit smoke
newimpact.Parent = workspace
newimpact:MoveTo(Vector3.new(rightleg.Position.X,rightleg.Position.Y/2.5,rightleg.Position.Z))
newimpact.Hitbox.Touched:Connect(touchhitbox)
for i = 0,1,.01 do
pos.CFrame = pos.CFrame:Lerp(pos.CFrame:ToWorldSpace(CFrame.new(0,-3/100,0)),i)
task.wait(.001)
end
hittable[newplr] = nil
newimpact:Destroy()
debouncetable[plr] = nil
end
end)
end
end
end
RS.Impact.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char.Humanoid
local HRP = char.HumanoidRootPart
local rightleg = char["Right Leg"]
spawnimpact(rightleg, humanoid, char, plr)
end)
Update:
I tried debugging both possibilites of the touchhitbox function but nothing happens in the output.
Update 2:
When I tested on a local server, the server sometimes showed the newplr value for nil.
Update 3:
I’m getting the error table index is nil on line 53.(Commented at bottom)
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local StompAnim = SS.Animations.Stomp
local impact = RS.ImpactModel
local debouncetable = {}--USE THE DEBOUNCETABLE TECHNIQUE
local dummytable = {}
local hittable = {}
local function spawnimpact(rightleg, humanoid, char, plr)
local newplr
local function touchhitbox(hit) --Damaging
newplr = Players:GetPlayerFromCharacter(hit.Parent)
print(newplr)
if newplr and not hittable[newplr] and not hit.Parent.Humanoid:IsDescendantOf(plr.Character) then
hittable[newplr] = newplr
hit.Parent.Humanoid:TakeDamage(25)
elseif newplr == nil and not dummytable[hit.Parent] and hit.Parent.Name == "Rig" then
dummytable[hit.Parent] = hit.Parent
hit.Parent.Humanoid:TakeDamage(25)
dummytable[hit.Parent] = nil
end
end
local animtrack = humanoid:LoadAnimation(StompAnim)
local newimpact = impact:Clone()
local pos = newimpact.PrimaryPart
local raycast = workspace:Raycast(rightleg.Position,rightleg.CFrame.UpVector * -10) --Raycast material
if humanoid:GetState() == Enum.HumanoidStateType.Running or humanoid:GetState() == Enum.HumanoidStateType.Landed then --Check if not jumping or freefall
if plr and not debouncetable[plr] then --Check if player is not already in cooldown
debouncetable[plr] = plr --put in cooldown
animtrack:Play() -- play anim
newimpact.Hitbox.Quake:Play() -- play sound
animtrack.Stopped:Connect(function()
if raycast then
for i,v in pairs(newimpact:GetChildren()) do
v.BrickColor = raycast.Instance.BrickColor
v.Material = raycast.Material
end
newimpact.Area.SmokeEffect:Emit(30) --Emit smoke
newimpact.Parent = workspace
newimpact:MoveTo(Vector3.new(rightleg.Position.X,rightleg.Position.Y/2.5,rightleg.Position.Z))
newimpact.Hitbox.Touched:Connect(touchhitbox)
for i = 0,1,.01 do
pos.CFrame = pos.CFrame:Lerp(pos.CFrame:ToWorldSpace(CFrame.new(0,-3/100,0)),i)
task.wait(.001)
end
newimpact:Destroy()
debouncetable[plr] = nil
hittable[newplr] = nil -- LINE 53!!
end
end)
end
end
end
RS.Impact.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char.Humanoid
local HRP = char.HumanoidRootPart
local rightleg = char["Right Leg"]
spawnimpact(rightleg, humanoid, char, plr)
end)