Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --LocalScript, put it in game.StarterGui
- local player = game:GetService("Players").LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local remote = game:GetService("ReplicatedStorage"):WaitForChild("Drop_Tool") --add a RemoteEvent object into game.ReplicatedStorage else this code won't run
- local enabled = true
- local UIS = game:GetService("UserInputService")
- UIS.InputBegan:Connect(function(input,gameProcessed)
- 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.
- 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
- enabled = false --turn off enable to tell the line above that it's off and running
- remote:FireServer() --will call the function of the RemoteEvent that's on a server-sided script (Script) instead of client-sided script (LocalScript)
- 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)
- enabled = true --set enabled back to true once cool down is over
- end
- end)
- --[[
- COPY AND CUT THE CODE BELOW TO A Script object PLACED IN game.ServerScriptService
- ]]
- local remote = game.ReplicatedStorage:WaitForChild("Drop_Tool")
- remote.OnServerEvent:Connect(function(player) --will wait for the client-side (LocalScript) to call the function for the server to execute
- local character = player.Character or player.CharacterAdded:Wait()
- 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)
- 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)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement