Advertisement
Guest User

[ROBLOX] Drop Tool Script

a guest
Feb 1st, 2019
13,989
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 1
  1. --LocalScript, put it in game.StarterGui
  2. local player = game:GetService("Players").LocalPlayer
  3. local character = player.Character or player.CharacterAdded:Wait()
  4.  
  5. local remote = game:GetService("ReplicatedStorage"):WaitForChild("Drop_Tool") --add a RemoteEvent object into game.ReplicatedStorage else this code won't run
  6.  
  7. local enabled = true
  8.  
  9. local UIS = game:GetService("UserInputService")
  10.  
  11. UIS.InputBegan:Connect(function(input,gameProcessed)
  12.     if gameProcessed then return end --see if your keyboard is busy with something else, if it does then it will stop the code at this line.
  13.     if input.UserInputType = Enum.UserInputType.MouseButton2 and enabled then --see if the player clicked with MouseButton2, A.K.A. the right mouse button. check to see if the variable "enable" is true
  14.         enabled = false --turn off enable to tell the line above that it's off and running
  15.         remote:FireServer() --will call the function of the RemoteEvent that's on a server-sided script (Script) instead of client-sided script (LocalScript)
  16.         wait(1.5) --cool down of 1.5 seconds to yield the player and script from repeatedly sending calls to the RemoteEvent (which is bad and damaging if repeated extremely)
  17.         enabled = true --set enabled back to true once cool down is over
  18.     end
  19. end)
  20.  
  21. --[[
  22.     COPY AND CUT THE CODE BELOW TO A Script object PLACED IN game.ServerScriptService
  23. ]]
  24.  
  25. local remote = game.ReplicatedStorage:WaitForChild("Drop_Tool")
  26. remote.OnServerEvent:Connect(function(player) --will wait for the client-side (LocalScript) to call the function for the server to execute
  27.     local character = player.Character or player.CharacterAdded:Wait()
  28.     if character:FindFirstChildOfClass("Tool") then --will check if the avatar of the player has a tool equipped to it's avatar (this is default when you equip a tool from your player, don't worry)
  29.         character:FindFirstChildOfClass("Tool"):Destroy() --will destroy the tool from the avatar (don't worry, it will automatically unequip the tool and be safely placed in your backpack/inventory)
  30.     end
  31. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement