How do i make script that will delete a tool?

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.

2 Likes

Mabye you find is in toolbox

Im forgot script mabye is eat

1 Like
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:

Animator:LoadAnimation(animation)

1 Like

You can use this simple script

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.
image

5 Likes

I recommend using

local used = 3.1415
used = 0

rather then

local used = tool.Used
used.Value = 0

And they cant get player character because its a server, not a client. Sure, you can use script.Parent.Parent but that would break every time it dies.

But i didn’t think of that. Nice fellow coder!

Thanks, but i’m started just 3 weeks ago.

1 Like

It’s okay. You learn on the way :smiley:!

1 Like

I’ll check this out when i’m home! Thanks :slight_smile:

2 Likes

If you want animation, do the client server remote thing, its better to get the player like that.

2 Likes

if you want animation, hit me up

I already made animations for it. Thanks tho.

I meant as in scripting them to play

Ohhh. No thanks, i also have that already in my script.

1 Like

Aight, Aight. The devforum needs me to type a certain amount of characters.