So I’m making a knife script, but I have a problem. For some strange, arbitrary reason the thrown knives JUST WONT DESTROY THEMSELVES. I have no idea how or why, but it just won’t work.
Here is the relevant code. I’m including as much as possible because I have no idea what could be causing this.
throwRE.OnServerEvent:Connect(function(plr, mouseHit, scale)
local character = plr.Character
if not character or not character:FindFirstChild('Humanoid') then return end
if iscooldown then return end
iscooldown = true
knife.Cooldowned.Value = true
character.Humanoid:LoadAnimation(throwAnim):Play()
local knifeClone = handle:Clone()
knifeClone.Velocity = mouseHit.LookVector * (speed * scale)
knifeClone.Parent = workspace
knifeClone:WaitForChild('WeldConstraint'):Destroy()
handle.Transparency = 1
knifeClone.CFrame = CFrame.new(knifeClone.Position, mouseHit.LookVector * 300)
local bav = Instance.new("BodyAngularVelocity")
bav.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bav.AngularVelocity = knifeClone.CFrame:VectorToWorldSpace(Vector3.new(-400 * scale, 0, 0))
bav.Parent = knifeClone
game.ReplicatedStorage.ClientKnife:FireAllClients(knifeClone, knife.Parent)
knifeClone.Touched:Connect(function(touched)
if touched.Transparency < 1 and not knife.Parent:IsAncestorOf(touched) and not knifeClone.Anchored then
local humanoid = touched.Parent:FindFirstChild('Humanoid') or touched.Parent.Parent:FindFirstChild('Humanoid')
if humanoid then
humanoid:TakeDamage(100)
animator = humanoid:WaitForChild("Animator")
if humanoid.Health <= 0 then
local killtrack = animator:LoadAnimation(killanim)
killtrack:Play(.001)
end
end
knifeClone.Anchored = true
knifeClone.CFrame = CFrame.new(knifeClone.Position, touched.Position)
knifeClone:FindFirstChild('MeshPart').Transparency = 0
knifeClone.Transparency = 1
wait(cooldown)
knifeClone:Destroy()
end
end)
wait(cooldown)
iscooldown = false
knife.Cooldowned.Value = false
handle.Transparency = 0
end)
The knives are becoming Anchored and the transparency thing is working (it’s created so the knives are more likely to stick to the surface instead of floating a bit in front of it) but the knife isn’t destroying itself.
I’ve also tried creating a loop inside of the cloned knife that will destroy itself after being anchored, AND a script that will automatically clean out all anchored parts named “MeshPart” (the name of the cloned knife) and are parented directly to workspace. Neither work at all.
What on earth is happening?