Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make this script delete the tool after eating? (read desc)

Asked by 4 years ago

So This is an eating script I need it after you eat the item goes away I tried it did not work fell free! to redo the script I guess but I would like if you would teach me how to do this please.

local Tool = script.Parent;

enabled = true




function onActivated()
    if not enabled  then
        return
    end

    enabled = false
    Tool.GripForward = Vector3.new(-0.976,0,-0.217)
    Tool.GripPos = Vector3.new(.95,-0.76,1.4)
    Tool.GripRight = Vector3.new(0.217,0, 0.976)
    Tool.GripUp = Vector3.new(0,1,0)


    Tool.Handle.Eating:Play()

    wait(.8)

    local h = Tool.Parent:FindFirstChild("Humanoid")
    if (h ~= nil) then
        if (h.MaxHealth > h.Health + 1.6) then
            h.Health = h.Health + 1.6
        else    
            h.Health = h.MaxHealth
        end
    end

    Tool.GripForward = Vector3.new(-0.976,0,-0.217)
    Tool.GripPos = Vector3.new(0.3,0,0)
    Tool.GripRight = Vector3.new(0.217,0,-0.976)
    Tool.GripUp = Vector3.new(0,1,0)


local part = script.Parent.Cookie -- The variable

function 
    wait (0.01)
    part:Destroy()
end

    enabled = true

end




script.Parent.Activated:connect(onActivated)
0
You don't need another function to wait and destroy the cookie. AntiWorldliness 868 — 4y

2 answers

Log in to vote
0
Answered by
Lyphios 77
4 years ago
Edited 4 years ago

Add a separate script in the tool and try having this:

local Tool = script.Parent

Tool.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        wait()--change this value to how long the eating animation lasts
        script.Parent:Destroy()-- I'm not sure if I indented this correctly, experiment with it.
    end)
end)

Hope that helps

0
Scrap the part of your main script that's meant to destroy the tool, only do this if it interferes with anything else you wrote. Lyphios 77 — 4y
0
it did not work there is a line under tool JuzeyPlayz -83 — 4y
0
Then just define tool. I edited the script. Lyphios 77 — 4y
0
sadly it does not work. JuzeyPlayz -83 — 4y
View all comments (3 more)
0
Also, why do you only want to destroy part of the tool, instead of the tool itself? in your script you defined "part" as a part of the tool named Cookie, so why do you only want to destroy that? It would still leave the tool in the player's inventory. Lyphios 77 — 4y
0
Ok wait, let me test it in studio Lyphios 77 — 4y
0
I found it I made my own script and it worked thanks for the effort tho! JuzeyPlayz -83 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I did it myself guys here is the simply script!

local Tool = script.Parent;

enabled = true




function onActivated()
    if not enabled  then
        return
    end

    enabled = false
    Tool.GripForward = Vector3.new(-0.976,0,-0.217)
    Tool.GripPos = Vector3.new(.95,-0.76,1.4)
    Tool.GripRight = Vector3.new(0.217,0, 0.976)
    Tool.GripUp = Vector3.new(0,1,0)


    Tool.Handle.Eating:Play()



        wait(4)
if script.Parent then script.Parent:Destroy() end 



end



script.Parent.Activated:connect(onActivated)
0
Yeah, a simpler script helps. Lyphios 77 — 4y

Answer this question