I ran into an extremely annoying error, For some reason the knife tool I made cannot detect hitting a player on the first swing. There are no error's aside from:
17:33:35.149 - Replication: Can't create default object of type Players
I even put a print function after each "if" statement to see if the script made it that far, It doesn't detect the humanoid on the first swing, what's even weirder is if I stand still and continue to swing in the same spot after the first one didn't register none of them will, unless I move my character and try hitting the humanoid again. I did multiple server tests hitting the humanoid and ensuring the handle, which is the whole tool is touching the humanoid.
This is very annoying and I can't seem to find out what's wrong.
Knife Server Script
-- Made by Dekadrachm
-- Weapon Stats
-- Killer's speed boost given by the knife. Default speed is "16" * (speedboost) value.
speedboost = 1.25
-- Damage of the killer's knife.
damage = 50
-- Time before the killer can use the weapon again.
firerate = 1
-- Time before combo windo closes.
combowindow = .1
-- Amount of damage each combo multiplies by.
combodamage = 0
-- end
knife = script.Parent -- The knife.
handle = knife:WaitForChild("Handle") -- The handle.
event = knife:WaitForChild("RemoteEvent") -- The remote event.
Swoosh = handle:WaitForChild("Swoosh") -- Finds Sound
Swoosh1 = handle:WaitForChild("Swoosh1") -- Finds Sound
debris = game:GetService("Debris")
local lastclick = tick() -- Killer's last click.
local combo = 0 -- combo stages
-- This starts when the knife is "Equipped".
knife.Equipped:connect(function()
equipped = true -- States that the knife is equipped
combo = 1
local lastclick = tick() -- Killer's last click.
killer = knife.Parent -- States that the killer is the person holding the knife.
player = game.Players:GetPlayerFromCharacter(killer) -- Finds the player that is the killer.
humanoid = killer:FindFirstChild("Humanoid") -- Finds the killer's humanoid, the basis of the player.
if humanoid ~= nil then -- States if the killer's humanoid doesn't exist, then...
humanoid.WalkSpeed = humanoid.WalkSpeed * speedboost -- This sets the killer's speed to be multiplied by the speed boost.
else -- If the killer's humanoid, basis doesn't exist, then
killer = nil -- States the killer doesn't exist.
end -- The end of the "if" statment.
end) -- The end of the function.
-- This starts when the knife is "Un-Equipped".
knife.Unequipped:connect(function()
equipped = false -- States that the knife is unequipped.
combodamage = 0
if humanoid ~= nil then -- Checks to see if the killer's humanoid, basis exists, then...
humanoid.WalkSpeed = humanoid.WalkSpeed / speedboost -- Reverses the effects of the speed boost given for equipping the knife.
end -- The end of the "if" statment.
killer = nil -- States the killer doesn't exist.
humanoid = nil -- Stats the killer's humanoid, basis doesn't exist.
end) -- The end of the function.
-- This starts when the knife is "Activated" a.k.a when the user clicks.
knife.Activated:connect(function()
used = true
local clickdelta = tick() - lastclick -- How long ago did the user last click.
if clickdelta > firerate then -- If the last time the user clicked is greater than "firerate" then...
lastclick = tick()
hithumanoids = {}
if clickdelta < firerate + combowindow then
combo = (combo + 1) % 2
else
combo = 0
end
if player ~= nil then
if combo == 0 then
event:FireClient(player, "RunAnimation", "slash")
Swoosh:Play()
combodamage = 1
elseif combo == 1 then
event:FireClient(player, "RunAnimation", "stab")
Swoosh1:Play()
combodamage = 2
end
end
end
-- This starts when the knife touches an object. All parts of the tool must be inside the handle.
handle.Touched:connect(function(hit) -- Attaches "hit" to whatever is touched with the knife, can then be used to find certain children.
print("0")-- the script didnt make it here on first swing in the same location.
if equipped == true and killer ~= nil and humanoid ~= nil and humanoid.Health > 0 and hit ~= nil and not hit:isDescendantOf(killer) and used == true then -- This starts if the knife is equppied, the killer exists, the killer's humanoid exists, the killer isn't dead, the killer isn't hitting themselves.
print("1")
local killertarget = hit.Parent:FindFirstChild("Humanoid")-- This locates the player's humanoid, the basis of a player.
if killertarget ~= nil and killertarget.Health > 0 and not hithumanoids[killertarget] and used == true then -- This checks to make sure the target exists and that it has health.
print("2")
hithumanoids[killertarget] = true
killertarget:TakeDamage(damage * combodamage) -- The amount of damage the knife does.
print("damage should have been done")
for _, v in pairs(killertarget:GetChildren()) do
if v ~= nil and v.Name == "tagged" then
v:Destroy()
end
end
local tag = Instance.new("ObjectValue")
tag.Name = "tagged"
tag.Value = player
tag.Parent = killertarget
debris:AddItem(tag, 3)
end -- The end of the second "if" statment.
end -- The end of the first "if" statment.
end) -- The end of the function.
wait(1)
used = false
end)-- The end of the function.
-- End Of Script
You can see my prints near where the error is, it never passed any of them on the first swing or any of the swings after that if I stood in the same spot from my first swing.
Knife local script.
-- Made by Dekadrachm
local knife = script.Parent
event = knife:WaitForChild("RemoteEvent")
humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
event.OnClientEvent:connect(function(...)
humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local tuple = {...}
if tuple [1] == "RunAnimation" then
animation = knife:FindFirstChild(tuple [2])
if animation ~= nil and humanoid ~= nil then
loadedanimation = humanoid:LoadAnimation(animation)
if loadedanimation ~= nil then
loadedanimation:Play()
if themouse ~= nil then
themouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
wait(1)
themouse.Icon = "rbxasset://textures\\GunCursor.png"
end
end
end
end
end)
knife.Equipped:connect(function(mouse)
themouse = mouse
if humanoid ~= nil then
local idleanimation = knife:FindFirstChild("idle")
if idleanimation ~= nil and humanoid ~= nil then
if loadedanimation ~= nil then
loadedidleanimation:Stop()
end
else
loadedidleanimation = humanoid:LoadAnimation(idleanimation)
if loadedidleanimation ~= nil then
loadedidleanimation:Play()
elseif loadedidleanimation == nil then
print("error with knife idle")
end
end
end
if themouse ~= nil then
themouse.Icon = "rbxasset://textures\\GunCursor.png"
end
end)
knife.Unequipped:connect(function()
if loadedidleanimation ~= nil then
loadedidleanimation:Stop()
end
loadedanimation = nil
animation = nil
end)
I don't know if this is relevant but I included it anyways, this is all of the knife's scripts. It uses a remote event in preparation for filtering.
I hope I get answers, the last questions I had seemed to be ignored.
Thanks in advanced.
How can I get the first hit of my knife tool to be detected when hitting a humanoid.
It is only the first hit in the instance, I can hit the humanoid, it not do any damage, move hit the humanoid then it does damage and I can kill it. When it respawns I can do it again with out issue.

4 comments
you need to ditch that script bruh, it doesnt work no more
what do you mean
Is this even your script?
Yes, I finally got it to work