Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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! :)

31 comments

0

The line where it says "script.Parent.Activated", is it a screengui?

0

No, there is no Gui involved with in the script or tool.

0

What I mean is, is it a script or localscript and also is it's parent a screengui?

0

Its a script, and no it's not a parent to a screengui.

0

I'm confused, how can it be activated when there is nothing activating it, are you using a click function like "MouseButton1Click"?

0

Okay, what is the classname for the script's parent? Is it a model, etc

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.

0

Class name? It's parent is the tool itself, that I can say. Forgive me for my ignorance.

0

For a better understand, do you mind screenshot the workspace, Where your script is and what parent is it under?

0

Yeah, give me a second. And I really appreciate for what your doing here.

0

No problem, I usually get more details to help out. For an example, https://prnt.sc/iww2fd

0

Alright, i've got the screenshot. Now how can show you it?

0

go to

0

go to prnt.sc and u can insert images.

0

My mistake, I was testing it on a block... :/

0

ohhh

0

you mean a part?

0

Ok, here is the actual thing. https://prnt.sc/j9pl2s The tool is called, "Tool"

0

So my idea was, who ever would be using the tool would click. The the script would use ZTZ (Animation) and load it.

0

ok, shouldn't be a hard one

0

So its not the script? But the placement?

0

I have tried many things to get this test right, but so far I haven't been so succesful.

0

script should work

0

So what am I missing?

0

Allow me to give this a try for a second

0

if you find any errors don't be afraid to tell me, I make mistakes as well.

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.

0

Any suggestion on where I should learn how to script so I know how to do this on my own in the future?

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.

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

0

Know where I can farther learn how to script so I may get better at scripting?

2 answers

✓ Accepted answer

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)

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.