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

Animation for Potion tool. Animation won't activate on clicking? What can I do to fix this?

Asked by 6 years ago

I'm trying to create a speed potion with an animation I have made with Animation Editor (R15). However, I think I may have done something wrong with the script,

local CanActivate = true
local player = game.Players.LocalPlayer
local character = player.Character

script.Parent.Activated:connect(function()
    if CanActivate = true then
        local animation = character.Humanoid:LoadAnimation(script.Parent.ZTZ)
        animation:Play()
    end
end)

The animation's name is ZTZ if your wondering what that's about. Also im very new to scripting so I may have made a stupid mistake. Any help would be greatly appreciated! :)

0
The line where it says "script.Parent.Activated", is it a screengui? IIApexGamerII 76 — 6y
0
No, there is no Gui involved with in the script or tool. mullenman 4 — 6y
0
What I mean is, is it a script or localscript and also is it's parent a screengui? IIApexGamerII 76 — 6y
0
Its a script, and no it's not a parent to a screengui. mullenman 4 — 6y
View all comments (27 more)
0
I'm confused, how can it be activated when there is nothing activating it, are you using a click function like "MouseButton1Click"? IIApexGamerII 76 — 6y
0
Okay, what is the classname for the script's parent? Is it a model, etc IIApexGamerII 76 — 6y
0
And here is where the stupid mistake may come in. My idea was is it would detect any activations with mouse clicking, buttons, or screen tapping. This would be my first time trying this, but this question has been going on for quite some time. mullenman 4 — 6y
0
Class name? It's parent is the tool itself, that I can say. Forgive me for my ignorance. mullenman 4 — 6y
0
For a better understand, do you mind screenshot the workspace, Where your script is and what parent is it under? IIApexGamerII 76 — 6y
0
Yeah, give me a second. And I really appreciate for what your doing here. mullenman 4 — 6y
0
No problem, I usually get more details to help out. For an example, https://prnt.sc/iww2fd IIApexGamerII 76 — 6y
0
Alright, i've got the screenshot. Now how can show you it? mullenman 4 — 6y
0
go to IIApexGamerII 76 — 6y
0
go to prnt.sc and u can insert images. IIApexGamerII 76 — 6y
0
My mistake, I was testing it on a block... :/ mullenman 4 — 6y
0
ohhh IIApexGamerII 76 — 6y
0
you mean a part? IIApexGamerII 76 — 6y
0
Ok, here is the actual thing. https://prnt.sc/j9pl2s The tool is called, "Tool" mullenman 4 — 6y
0
So my idea was, who ever would be using the tool would click. The the script would use ZTZ (Animation) and load it. mullenman 4 — 6y
0
ok, shouldn't be a hard one IIApexGamerII 76 — 6y
0
So its not the script? But the placement? mullenman 4 — 6y
0
I have tried many things to get this test right, but so far I haven't been so succesful. mullenman 4 — 6y
0
script should work IIApexGamerII 76 — 6y
0
So what am I missing? mullenman 4 — 6y
0
Allow me to give this a try for a second mullenman 4 — 6y
0
if you find any errors don't be afraid to tell me, I make mistakes as well. IIApexGamerII 76 — 6y
0
I don't know what to say. Your script looks much more complex than my own. Sorry if I have caused you any trouble. This is wonderful! :D Works perfectly. mullenman 4 — 6y
0
Any suggestion on where I should learn how to script so I know how to do this on my own in the future? mullenman 4 — 6y
0
Thank you, appreciate it. It need more functions for it to work, your scripting wasn't as bad as you think, you actually did pretty well, I used your scripting to finish off the script. IIApexGamerII 76 — 6y
0
Remember, do not hesitate to let me know if there is an error, you can use output to for more info. Scripts can break, so please if it has any problems just let me know. (Not saying I'm the best, but I'd love to get to be part of your projects.) IIApexGamerII 76 — 6y
0
Know where I can farther learn how to script so I may get better at scripting? mullenman 4 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Okay, so all you have to do is change the "script", to "LocalScript", then try putting in this code I've been working on inside the local script (it's a revised of your script but fixed i guess, i mean i'm not perfect, but it is working for me, instead of using your animation "since i do not know it", I used my own animation and found the test successful in studio.)

local Tool = script.Parent
local humanoid = nil
local connection = nil
local playing = false
activated = nil
local CanActivate = true
local player = game.Players.LocalPlayer
local character = player.Character

function onEquippedLocal(mouse)

    humanoid = Tool.Parent:FindFirstChild("Humanoid")
    activated = humanoid:LoadAnimation(Tool.ZTZ)
    connection = mouse.Button1Down:connect(activatedd)

end

function onUnequippedLocal()

    humanoid = nil

    if activated ~= nil then
        activated:Stop()
        activated:remove()
        activated = nil
    end

    connection:disconnect()

end

function activatedd()

    if playing then
        return
    end

    playing = true

    if CanActivate == true then
        local animation = character.Humanoid:LoadAnimation(script.Parent.ZTZ)
        animation:Play()
wait(10)--Change it to how long your animation is going to run
animation:Stop()--If your animation is a loop, you're going to need this
    playing = false

    end
end

Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)

Ad
Log in to vote
0
Answered by 6 years ago
local CanActivate = false
local ply = game.Players.LocalPlayer
local character = ply.Character
local m = ply:GetMouse()

script.Parent.Activated:connect(function()
    CanActivate = true
end)
script.Parent.Deactivate:connect(function()
    CanActivate = false
end)    

m.Button1Down:connect(function()
      if CanActivate == true then
        local animation = character.Humanoid:LoadAnimation(script.Parent.ZTZ)
        animation:Play()
    end
end)

Answer this question