I want to make this script Disabled = true if it's touched by a tool called Pickaxe
local ting = 0 function onTouched(hit) if ting == 0 then ting = 1 check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:findFirstChild("Cash") cash.Value = cash.Value +10 wait(1) script.Parent:clone().Parent = game.ReplicatedStorage script.Parent:remove() wait(5) game.ReplicatedStorage.Iron1:clone().Parent = game.Workspace game.ReplicatedStorage.Iron1:remove() end end end ting = 0 end script.Parent.Touched:connect(onTouched)
Is there any way you can make it so i must be touched by a certain part or tool then it gives you the money and disappears. EXPLAIN YOUR STEPS! PS. what the script is doing is if its touched by a humanoid give the humanoid 10 Cash remove the brick and clone it and put the clone in replicated storage then wait 5 sec and put it back in workspace
local ting = 0 function onTouched(hit) if ting == 0 then ting = 1 check = hit.Parent:FindFirstChild("Humanoid") -- hit.Parent would not work. I need to know the structure of the tool you are using, for example if it's a pickaxe and the head is a model and the handle is a model, if one of the head bricks hits it then you'd be getting that parts parent.. Which would be the model of the head. There would be no humanoid in here. if check ~= nil then if hit == "nameofpart" then -- That'd be the object that hits the brick. Call it something that nothing else is called and make sure that this is what everything that is allowed to hit it is called. local user = game.Players:GetPlayerFromCharacter(hit.Parent) -- Like the first comment, you need to use parenting more wisely. local stats = user:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:FindFirstChild("Cash") cash.Value = cash.Value + 10 wait(1) script.Parent:clone().Parent = game.ReplicatedStorage -- Why do this? ._. script.Parent:remove() wait(5) game.ReplicatedStorage.Iron1:clone().Parent = game.Workspace game.ReplicatedStorage.Iron1:remove() -- Why do this? Then it will only respawn once since the second time the function is called it's not going to find Iron1. end end end end ting = 0 end script.Parent.Touched:connect(onTouched)