Advertisement
HowToRoblox

KnifeServer

Jan 9th, 2021
5,389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local knife = script.Parent
  2. local handle = knife:WaitForChild("Handle")
  3.  
  4.  
  5. local throwRE = knife:WaitForChild("ThrowKnife")
  6.  
  7. local throwAnim = script:WaitForChild("ThrowAnimation")
  8.  
  9.  
  10. local cooldown = 2
  11. local isCooldown = false
  12.  
  13.  
  14. throwRE.OnServerEvent:Connect(function(plr, mouseHit)
  15.    
  16.    
  17.     local character = plr.Character
  18.    
  19.     if not character or not character:FindFirstChild("Humanoid") then return end
  20.    
  21.    
  22.     if isCooldown then return end
  23.     isCooldown = true
  24.    
  25.    
  26.     character.Humanoid:LoadAnimation(throwAnim):Play()
  27.    
  28.    
  29.     wait(0.4)
  30.    
  31.    
  32.     local knifeClone = handle:Clone()
  33.     knifeClone.Velocity = mouseHit.LookVector * 300
  34.    
  35.     knifeClone.Parent = workspace
  36.    
  37.     handle.Transparency = 1
  38.    
  39.     knifeClone.Throw:Play()
  40.    
  41.    
  42.     knifeClone.CFrame = CFrame.new(knifeClone.Position, mouseHit.LookVector * 300)
  43.    
  44.    
  45.     local bav = Instance.new("BodyAngularVelocity")
  46.     bav.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
  47.    
  48.     bav.AngularVelocity = knifeClone.CFrame:VectorToWorldSpace(Vector3.new(-400, 0, 0))
  49.     bav.Parent = knifeClone
  50.    
  51.    
  52.     game.ReplicatedStorage.ClientKnife:FireAllClients(knifeClone, knife.Parent)
  53.    
  54.    
  55.     knifeClone.Touched:Connect(function(touched)
  56.        
  57.         if touched.Transparency < 1 and not knife.Parent:IsAncestorOf(touched) then
  58.            
  59.             local humanoid = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")
  60.            
  61.             if humanoid then
  62.                
  63.                 humanoid.Health = 0
  64.             end
  65.            
  66.             knifeClone.Anchored = true
  67.            
  68.             knifeClone.Hit:Play()
  69.             wait(knifeClone.Hit.TimeLength)
  70.             knifeClone:Destroy()
  71.         end
  72.     end)
  73.    
  74.    
  75.     wait(cooldown - 0.4)
  76.     isCooldown = false
  77.     handle.Transparency = 0
  78. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement