Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Knife throw script not working?

Asked by 4 years ago
Edited 4 years ago

So I'm currently making a throwing knife script but when the remote server is fired an error popped up saying 20:06:36.909 - ServerScriptService.The World.Knife Throw:24: attempt to perform arithmetic (mul) on nil and number

There's a local script and a normal script

local script

local plr = game:GetService("Players").LocalPlayer

local rp = game:GetService("ReplicatedStorage")
local KnifeThrow = rp:WaitForChild("The World:Remotes"):WaitForChild("KnifeThrow")

local UIS = game:GetService("UserInputService")

local debounce = false
local cooldown = 0.75


UIS.InputBegan:Connect(function(input,IsTyping)
   if IsTyping then
      return
   elseif input.KeyCode == Enum.KeyCode.T then      
      if workspace:FindFirstChild(plr.Name.." Barrage") then
         return
      else
         if debounce == false then
            debounce = true

            local Character = plr.Character
            local Humanoid = Character:WaitForChild("Humanoid")

            local pos = Character.Humanoid.TargetPoint
            local LookAt = (pos - Character.Head.Position).Unit
            KnifeThrow:FireServer()
            wait(cooldown)
            debounce = false
         end
      end
   end
end)

Normal script

local rp = game:GetService("ReplicatedStorage")
local knife = rp:WaitForChild("The World:Remotes"):WaitForChild("KnifeThrow")
local Debris = game:GetService("Debris")

local TweenService = game:GetService("TweenService")

local damage = 6.25

knife.OnServerEvent:Connect(function(Player,LookAt)
   local Character = Player.Character
   local Humanoid = Character:WaitForChild("Humanoid")
   local HumanoidRP = Character:WaitForChild("HumanoidRootPart")

   local thr = Humanoid:LoadAnimation(script:WaitForChild("Throw"))
   thr:Play()

   local Folder = Instance.new("Folder",workspace)
   Folder.Name = Player.Name.." Knives"

   for i = 1, 3 do
      local knife0 = script.Knife:Clone()
      knife0.CFrame = Character:WaitForChild("Right Arm").CFrame
      knife0.Parent = Folder
      knife0.Velocity = LookAt * 30
      local fly = Instance.new("BodyForce",knife0)
      fly.Force = Vector3.new(0,knife0:GetMass()*196.2,0)
      game.Debris:AddItem(knife0,10)
      wait()
      knife0.Touched:Connect(function()
         wait(15)
         knife0:remove()
      end)
   end
end)


0
You didn't pass the LookAt variable. Ziffixture 6913 — 4y

1 answer

Log in to vote
1
Answered by
FirezDevv 162
4 years ago

Looks like you forgot to pass the lookat variable

heres a little fix for your at line 27 of the local script

  KnifeThrow:FireServer(LookAt)
0
oh no wonder why thanks! I was just tired Eric_pokemon 133 — 4y
Ad

Answer this question