so in a serverscript inside my "ThrownKnife" (parent) this is my code
so the elseif statement is supposed to be when the knife (for example) hits a wall to destroy itself... but the knife only destroys when hitting a player and ignores the elseif argument entirely (the if argument that checks for humanoids and players)
base = ThrownKnife
EDITED AT 7:32PM
base=script.Parent
tag=base.OwnerTag
local event = game:GetService("ReplicatedStorage")["KnifeDataTransferEvent"]
base.Touched:Connect(function(part)
if part:IsDescendantOf(tag.Value.Character)==false then
if part.Parent:FindFirstChild("Humanoid") or part.Parent:GetPlayerFromCharacter() then
local enemy=part.Parent
event:FireClient(tag.value,"Damage",base,enemy)
elseif not part.Parent:FindFirstChild("Humanoid") then
base:Destroy()
end
end
end)
what did i do wrong here? (keep in mind this is created through the server in another script, here)
event = game:GetService("ReplicatedStorage")["KnifeEvent"]
storage=game:GetService("ReplicatedStorage")
event.OnServerEvent:Connect(function(player, mode, handle, mousepos)
if mode=="Stab"then
print("stab event happening")
handle.knifestab:Play()
handle.Swing.Value=true
wait(0.2)
handle.Swing.Value=false
elseif mode=="Throw" then
local a = storage["ThrownKnife"]:Clone()
a.Parent=workspace
a.CFrame=CFrame.new(handle.Position,mousepos)
a.Velocity=a.CFrame.lookVector * (300)
a.ThrowHandling.Disabled=false
a.ThrowHandling.Delete.Disabled=false
a["OwnerTag"].Value=player
elseif mode=="Damage" then
mousepos:FindFirstChild("Humanoid"):TakeDamage(100)
end
end)
ALSO KEEP IN MIND: i made another script that destroys it automatically after 5 seconds but it doesnt relate to this so yeah...

5 comments
problem: knife does destroy but it does not even exist (the knife destroys as soon as it spawns because it touches my character)
you can do a check. if part is descendant of the player then don't destroy
yeah thats what line 5 is for (to check if its touching the player or not to even do anything else)
then put the destroy after line 5 lol
its wonky but it kills so ill just mark as answered and build off there