Advertisement
Dark_Ace

Catching Script

Sep 19th, 2024
2,762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | Gaming | 0 0
  1. -- Script in ServerScriptService
  2. local serverStorage = game:GetService("ServerStorage")
  3. local players = game:GetService("Players")
  4.  
  5. local footballPrefab = serverStorage:WaitForChild("Football")
  6. local spawner = workspace:WaitForChild("FootballSpawner")
  7.  
  8. local function giveTool(player)
  9.     if player.Character then
  10.         local tool = footballPrefab:Clone()
  11.         tool.Parent = player.Backpack
  12.     end
  13. end
  14.  
  15. local function onTouched(hit)
  16.     local character = hit.Parent
  17.     local player = players:GetPlayerFromCharacter(character)
  18.  
  19.     if player then
  20.         giveTool(player)
  21.     end
  22. end
  23.  
  24. spawner.Touched:Connect(onTouched)
  25.  
  26. local function onFootballTouched(hit)
  27.     local character = hit.Parent
  28.     local player = players:GetPlayerFromCharacter(character)
  29.  
  30.     if player and not player.Backpack:FindFirstChild("Football") and not player.Character:FindFirstChild("Football") then
  31.         local football = hit.Parent
  32.         if football:IsA("Tool") and football.Name == "Football" then
  33.             football.Parent = player.Backpack
  34.         end
  35.     end
  36. end
  37.  
  38. workspace.ChildAdded:Connect(function(child)
  39.     if child:IsA("Tool") and child.Name == "Football" then
  40.         child.Handle.Touched:Connect(onFootballTouched)
  41.     end
  42. end)
  43.  
  44. -- ServerStorage > Tool > Script for Tool
  45. local tool = script.Parent
  46. local handle = tool:WaitForChild("Handle")
  47.  
  48. local THROW_POWER = 50
  49. local MAX_THROW_DISTANCE = 100
  50.  
  51. local function onActivated()
  52.     local player = game.Players:GetPlayerFromCharacter(tool.Parent)
  53.     if not player then return end
  54.  
  55.     local character = player.Character
  56.     if not character then return end
  57.  
  58.     local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  59.     if not humanoidRootPart then return end
  60.  
  61.     local throwDirection = humanoidRootPart.CFrame.LookVector
  62.  
  63.     tool.Parent = workspace
  64.     handle.CanCollide = true
  65.  
  66.     local bodyVelocity = Instance.new("BodyVelocity")
  67.     bodyVelocity.Velocity = throwDirection * THROW_POWER
  68.     bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  69.     bodyVelocity.P = 1250
  70.     bodyVelocity.Parent = handle
  71.  
  72.     game.Debris:AddItem(bodyVelocity, 0.1)
  73.  
  74.     wait(0.1)
  75.     handle.CanCollide = true
  76. end
  77.  
  78. tool.Activated:Connect(onActivated)
  79.  
  80. -- Local Script for Tool
  81. local tool = script.Parent
  82. local players = game:GetService("Players")
  83. local userInputService = game:GetService("UserInputService")
  84.  
  85. local function onEquipped()
  86.     local player = players.LocalPlayer
  87.     local character = player.Character
  88.     if not character then return end
  89.  
  90.     local humanoid = character:FindFirstChildOfClass("Humanoid")
  91.     if not humanoid then return end
  92.  
  93.     humanoid.WalkSpeed = 16
  94. end
  95.  
  96. local function onUnequipped()
  97.     local player = players.LocalPlayer
  98.     local character = player.Character
  99.     if not character then return end
  100.  
  101.     local humanoid = character:FindFirstChildOfClass("Humanoid")
  102.     if not humanoid then return end
  103.  
  104.     humanoid.WalkSpeed = 16
  105. end
  106.  
  107. tool.Equipped:Connect(onEquipped)
  108. tool.Unequipped:Connect(onUnequipped)
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement