Ok but using just a Script is the better way to do it so he doesen’t get confused with remoteevents.
@NinjaFurfante07 @ThePoisonFish
I’ve gotten it work with with the help of @ratioed_fireball , but I don’t know how to make it spin. I was thinking BodyMovers (if it’s possible), but I don’t know how.
Use BodyAngularVelocity and change the maxtorque and the rotation as you need.
Hello friend, this is definitely a bug, however I think you should look into magnitude.
if (player.Character.HumanoidRootPart.Position - knife.Position).Magnitude <= range then
return
end
Unfortunately that won’t work as the knife is anchored in order for the tween to work, are there any other ways?
Use CFrame.Angles() and multiply the knife’s cframe by your desired angle. (Obviously tweening it too) ,Actually you should tween the knife’s goal CFrame and multiply it by CFrame.Angles().
I don’t know how CFrame.Angles works, could you give me an example?
CFrame.Angles changes the tilt of the X,Y,Z of the CFrame in radians. So convert the radians to degrees with math.rad().
An example is : Part.CFrame = CFrame(Part.Position)*CFrame.Angles(0,math.rad(90),0).
I believe this will change the part’s Y rotation by 90 degrees.
Where would I place something like that in my code? I don’t know where to put it so that it would work and not cause issues.
You said that you tweened the knife position? I suggest instead of tweening position you tween the CFrame.
CFrame = CFrame.new(-your-position-)*CFrame.Angles(-your-angles-). So both rotation and position will be tweened.
I think I’m tweening the CFrame, but I cant be sure.
Here’s my tweening part of my code:
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)} -- properties
kcloneHitPart.Parent = kclone
local Weld = Instance.new("Weld")
Weld.Part0 = kcloneHitPart
Weld.Part1 = kclone
Weld.Parent = kcloneHitPart
kcloneHitPart.Anchored = false
kclone.Anchored = false
local tween = ts:Create(kclone, tweeninfo, prop)
tween:Play()
So for the properties I would just add in the angles?
Yes exactly, but it won’t include the lookvector unless you want it.
If you wanted to add the rotation with the knife looking at the target multiply the cframe with (CFrame.LookAt(HumanoidRootPart,mouseHit)-CFrame.LookAt(HumanoidRootPart,mouseHit).Position) . This will leave you with only the CFrame rotation i think it works, not sure.
That part didn’t work, but using
I was able to get it to rotate. However, tweens aren’t giving me quite the result I wanted, so I was wondering if you could help me with another problem.
I tried using Velocity and BodyAngularVelocity, and that looked promising, but there were 2 problems. 1, the knife anchored itself weirdly, and the accuracy was inconsistent.
I’m wondering if there’s a way to fix that?
Code
local k = script.Parent
local handle = k:WaitForChild("Handle")
local throwevent = k:WaitForChild("ThrowKnife")
local throwanim = script:WaitForChild("ThrowAnimation")
local db = 2
local isdb = false
local readytime = 0.55
throwevent.OnServerEvent:Connect(function(plr, mouseHit)
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)
local kclone = handle:Clone()
kclone.Velocity = mouseHit.LookVector * 300
kclone.Parent = workspace
handle.Transparency = 1
kclone.CFrame = CFrame.new(kclone.Position, mouseHit.LookVector * 300)
local bav = Instance.new("BodyAngularVelocity")
bav.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bav.AngularVelocity = kclone.CFrame:VectorToWorldSpace(Vector3.new(-400,0,0))
bav.Parent = kclone
game.ReplicatedStorage.Events.ClientKnife:FireAllClients(kclone, k.Parent)
kclone.Touched:Connect(function(touched)
if touched.Transparency < 1 and not k.Parent:IsAncestorOf(touched) then
kclone.Anchored = true
local hum = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")
if hum then
hum.Parent:BreakJoints()
end
wait(2)
kclone:Destroy()
end
end)
wait(db - 0.25)
isdb = false
handle.Transparency = 0
end)
Thanks!
Oh yeah, you’re doing it server sided. You should set the network ownership of the knife to the player by using a for i,v loop to get all the baseparts of the knife then use :SetNetworkOwner() to the player. It will reduce lag and stutter for the knife as the performance is based on the player’s hardware. You can set the bodymovers client sided as it will replicate if you set network ownership.
Also touched event isn’t that reliable, if i were you i would really raycast the trajectory as the collision will already be predicted.
The knife only has 1 part, but how would I set the Network Owner? Do you set it to the player themselves, or the character?
You set the knife’s part by doing Part:SetNetworkOwner(player).
I’m not sure if you can set it through client scripts though.
I don’t think you can change it locally either, but I’m running my knife throw in a server-sided script, so I think that would work.
Yes, use the OnServerEvent plr parameter as the player for networkowner then it will work perfectly.
Setting the network owner made the anchoring (it anchores way after it touches something) even worse, and the accuracy issue was not fixed either.
Code:
local k = script.Parent
local handle = k:WaitForChild("Handle")
local throwevent = k:WaitForChild("ThrowKnife")
local throwanim = script:WaitForChild("ThrowAnimation")
local db = 2
local isdb = false
local readytime = 0.55
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)
local kclone = handle:Clone()
kclone.Velocity = mouseHit.LookVector * 300
kclone.Parent = workspace
kclone:SetNetworkOwner(plr)
handle.Transparency = 1
kclone.CFrame = CFrame.new(kclone.Position, mouseHit.LookVector * 300)
local bav = Instance.new("BodyAngularVelocity")
bav.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bav.AngularVelocity = kclone.CFrame:VectorToWorldSpace(Vector3.new(-400,0,0))
bav.Parent = kclone
game.ReplicatedStorage.Events.ClientKnife:FireAllClients(kclone, k.Parent)
kclone.Touched:Connect(function(touched)
if touched.Transparency < 1 and not k.Parent:IsAncestorOf(touched) then
print("touched")
kclone.Anchored = true
local hum = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")
if hum then
hum.Parent:BreakJoints()
end
wait(2)
kclone:Destroy()
end
end)
wait(db - 0.25)
isdb = false
handle.Transparency = 0
end)