Advertisement
Er1x_Official

Potion Server Script

Mar 22nd, 2022
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. local tool = script.Parent -- the tool, parent of this script
  2. local handle = tool:WaitForChild("Handle",1) -- the handle in the tool
  3. local liquid = handle:WaitForChild("Liquid",1) -- the 'liquid' in the tool
  4. local sound = handle:WaitForChild("Sound",1) -- the 'sound' effect
  5.  
  6. local debris = game:GetService("Debris") -- timed destroy
  7.  
  8. local oncd = false -- cooldown boolean
  9. local cooldown = 1 -- cooldown time
  10. local maxuses = 3 -- maximum use of the potion
  11. local uses = 0 -- amount of use of the potion
  12.  
  13. local heal = 30 -- health potion, amount to heal
  14.  
  15. function effect() -- activate the effect
  16.     local humanoid = tool.Parent:FindFirstChildOfClass("Humanoid") -- find the 'humanoid'
  17.     if humanoid then -- checking if the 'humanoid' is there
  18.         humanoid.Health = humanoid.Health + heal -- adding the amount to heal
  19.         local cloneS = sound:Clone()
  20.         cloneS.PlayOnRemove = true -- play the sound on remove
  21.         cloneS.Parent = handle -- parent of the sound
  22.        
  23.         cloneS:Destroy() -- play the sound
  24.     end
  25. end
  26.  
  27. function activate()
  28.     if uses < maxuses and oncd == false then -- checking the times the tool was used and checking the if the tool is on cooldown too
  29.         uses = uses + 1
  30.         oncd = true
  31.        
  32.         effect()
  33.         task.delay(cooldown,function()
  34.             oncd = false
  35.         end)
  36.        
  37.         liquid.Transparency = uses/maxuses
  38.        
  39.         if uses >= maxuses then
  40.             debris:AddItem(tool,sound.TimeLength+.5)
  41.         end
  42.     end
  43. end
  44.  
  45. tool.Activated:Connect(activate)
  46. -- Made by TrolledTrollage, 3/22/2022 (Subscribe to Er1x on Youtube)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement