I’ve created a throwable knife, but I have some issues. The knife isn’t touching anything, when it looks like it is. I assume that’s because I’m using tweens, but I still don’t understand why.
Code
local k = script.Parent
local handle = k:WaitForChild("Handle")
local ts = game:GetService("TweenService")
local throwevent = game.ReplicatedStorage.Events:WaitForChild("KnifeThrow")
local throwanim = script:WaitForChild("ThrowAnimation")
local db = 2
local isdb = false
local clones = 0
local readytime = 0.7
throwevent.OnServerEvent:Connect(function(plr, mouseHit)
print("recieved")
local char = plr.Character
if not char or not char:FindFirstChild("Humanoid") then return end
if isdb then return end
isdb = true
char.Humanoid:LoadAnimation(throwanim):Play()
wait(readytime)
kclone = handle:Clone()
-- kclone.Velocity = mouseHit.LookVector * 300
--kclone.AssemblyLinearVelocity = CFrame.lookAt(kclone.Position, mouseHit) * 100
--kclone.AssemblyLinearVelocity = CFrame.lookAt(kclone.Position, mouseHit) * Vector3.new(100,0,0)
kclone.CanCollide = true
kclone.Parent = workspace
handle.Transparency = 1
-- kclone.CFrame = CFrame.new(kclone.Position, mouseHit.LookVector * 300)
--local bav = Instance.new("BodyVelocity")
-- bav.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
--bav.Velocity = kclone.CFrame.rightVector*100
--bav.Parent = kclone
-- game.ReplicatedStorage.Events.KnifeThrow:FireAllClients(kclone, k.Parent)
--kclone.Velocity = (script.Parent.Parent:FindFirstChild("Humanoid").TargetPoint - kclone.CFrame.p).unit * 100
-- set the orientation to the direction it is being thrown in
-- kclone.CFrame = CFrame.new(kclone.CFrame.p, kclone.CFrame.p + kclone.Velocity) * CFrame.Angles(0, 0, math.rad(-90))
--local floatingForce = Instance.new('BodyForce', kclone)
-- floatingForce.force = Vector3.new(0, 196.2 * kclone:GetMass() * 0.98, 0)
local function DecideTweenTime(mag)
local tweeninfo = TweenInfo.new(mag / 70)
return tweeninfo
end
-- local tweeninfo = TweenInfo.new(1)
-- if ((char.HumanoidRootPart - mouseHit.Position).magnitude) > 25 then
-- tweeninfo = TweenInfo.new(1)
--elseif (char.HumanoidRootPart) -- And so on
-- end
local tweeninfo = DecideTweenTime((char.HumanoidRootPart.Position - mouseHit).magnitude)
--kclone:SetNetworkOwner(nil)
--local tweeninfo = TweenInfo.new(.1, Enum.EasingStyle.Linear)
local prop = {CFrame = CFrame.new(mouseHit)}
kclone.Anchored = true
local tween = ts:Create(kclone, tweeninfo, prop)
tween:Play()
-- kclone.CFrame = CFrame.lookAt(kclone.Position, mouseHit)
--kclone.AssemblyLinearVelocity = kclone.CFrame.LookVector * 200
kclone.Touched:Connect(function(touched)
-- print(touched.Name)
if touched.Transparency < 1 and not k.Parent:IsAncestorOf(touched) then
print("touched")
kclone.Anchored = true
kclone.CanCollide = false
local hum = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")
--print(touched.Name)
if hum then
hum.Parent:BreakJoints()
end
wait(2)
print("about to destroy!")
kclone:Destroy()
end
end)
wait(db - readytime)
isdb = false
handle.Transparency = 0
end)
I added a print statement in the touched: print("touched")
, and it isn’t running.
Video:
https://gyazo.com/b7cdc7a898d60dd7ffa7aa81c1b34873
Thanks!