Basically, I'm scripting a throwable knife called a kunai in FE. Here's the client-sided code.
UIS.InputEnded:connect(function(input, gpe) if input.KeyCode == Enum.KeyCode.R and not gpe and SecondaryCount.Value > 0 and equipsecondary == false and putawaysecondary == true and isslashing == false then equipsecondary = false putawaysecondary = false isthrowing = true zoom = false SecondaryEvents:WaitForChild("Throw"):FireServer() wait(.7) isthrowing = false equipsecondary = true while camera.FieldOfView < 70 do wait(.01) camera.FieldOfView = camera.FieldOfView + 1 end end end)
Here's the server-sided code.
SecondaryEvents:WaitForChild("Throw").OnServerEvent:connect(function(plr) local mouse = plr:GetMouse() local Throw = SecondaryAnims:WaitForChild("Throw") local ThrowAnim = plr.Character:WaitForChild("Humanoid"):LoadAnimation(Throw) ThrowAnim:Play() wait(.5) if plr.Character:WaitForChild("Right Arm"):findFirstChild("Metal") then plr.Character:WaitForChild("Right Arm"):findFirstChild("Metal"):Destroy() end
if plr:WaitForChild("SecondaryWeapon").Value == 1 then
plr:WaitForChild("SecondaryCount").Value = plr:WaitForChild("SecondaryCount").Value - 1
local KunaiClone = SecondaryWeapons:WaitForChild("ThrowKunai"):Clone()
KunaiClone.Name = "Metal"
KunaiClone.Parent = workspace
local pos = plr.Character.Torso.Position
local focus = mouse.Hit.p
KunaiClone.CFrame = CFrame.new(pos,focus)
KunaiClone.CFrame = KunaiClone.CFrame+KunaiClone.CFrame.lookVector * 5
local KunaiVelocity = Instance.new("BodyVelocity")
KunaiVelocity.Parent = KunaiClone
KunaiVelocity.velocity = KunaiClone.CFrame.lookVector * 120
KunaiClone.CFrame = KunaiClone.CFrame * CFrame.Angles(math.pi/2, math.pi/2, 0)
local throwsound = KunaiClone.ThrowSound
throwsound:Play()
elseif plr:WaitForChild("SecondaryWeapon").Value == 2 then
plr:WaitForChild("SecondaryCount").Value = plr:WaitForChild("SecondaryCount").Value - 1
local KunaiClone = SecondaryWeapons:WaitForChild("ThrowMinatoKunai"):Clone()
KunaiClone.Name = "Metal"
KunaiClone.Parent = workspace
local pos = plr.Character.Torso.Position
local focus = mouse.Hit.p
KunaiClone.CFrame = CFrame.new(pos,focus)
KunaiClone.CFrame = KunaiClone.CFrame+KunaiClone.CFrame.lookVector * 5
local KunaiVelocity = Instance.new("BodyVelocity")
KunaiVelocity.Parent = KunaiClone
KunaiVelocity.velocity = KunaiClone.CFrame.lookVector * 120
KunaiClone.CFrame = KunaiClone.CFrame * CFrame.Angles(0, 0, 0)
local throwsound = KunaiClone.ThrowSound
throwsound:Play()
end
end)
Yes, I am aware now that GetMouse() doesn't work unless it's in a localscript. I don't know how to script an FE alternative.

2 comments
Send Mouse.Hit through a RemoteEvent or a RemoteFunction.
You forgot formatting for the client sided script