So i want to make script which can delete a tool of the player after a couple of clicks.
Is there a way to detect these clicks and if it detected 3 clicks, the tool will remove from the player. I want to use this for in game items like food and drinks.
local tool = script.Parent --Tool
local count = 0 --Varaible for count
function toolActivated() --Function
count+=1 --Add 1 to count variable
if count > 3 then --If the count is greater then 3 do this
tool:Destroy() --Tool will get destroyed
end
end
Use a remote event to fire it on the server if neccessary
If you are, do this in the server:
local tool = script.Parent --Tool
local remote = tool.RemoteEvent --Event that will be fired
local count = 0
remote.OnServerEvent:Connect(function() --When this happened, do this
count+=1 --Add 1 to count variable
if count >= 3 then --If the count is greater or equal to 3 then do this
tool:Destroy() --Tool will get destroyed
end
end)
Client:
local tool = script.Parent --Tool
function activated()
local remote = tool.RemoteEvent --Event that will be fired
remote:FireServer() --Fire remote event
end
tool.Activated:Connect(activated)
Doing it on the server will make other players see it, so I recommend it.
You can make Animations using:
local Used = script.Parent.Used
Used.Value = 0
script.Parent.Activated:Connect(function()
Used.Value = Used.Value + 1 --When a player used item, this will add the time that player used the item
if Used.Value >= 3 then --If the time played used the item more or equal 3, the item will delete
script.Parent:Destroy()
end
end)
And your script must be having both of these to make the wanted tool working correctly.