Animation not playing

Its a simple script meant to play when someone left clicks but its not working

local Rig = workspace.TemplateR6
local Rstor = game:GetService("ReplicatedStorage")
local Orb = Rig.Humanoid:LoadAnimation(14143584179)
local Isactive = false
local UIS = game:GetService("UserInputService")

if UIS.UserInputType == Enum.UserInputType.MouseButton1 then
	function PlayAnim()
		if Isactive == false then
			Isactive = true
			Orb:Play()
			wait(0.917)
			Isactive = false
		end
	end
end
UIS.InputBegan:Connect(PlayAnim(Enum.UserInputType.MouseButton1))```

The main reason this does not work is because the function your calling is nested meaning this

cannot see the PlayAnim function, I recommend taking the PlayAnim function out of the if statement and moving the if statement either inside the PlayAnim function or putting it in the trigger.

I changed your code a little so it functions properly, i’ll put comments so you know what i changed

local Rig = workspace.TemplateR6
local Rstor = game:GetService("ReplicatedStorage")
local anim = Instance.new("Animation") -- creating a new animation object
anim.AnimationId = "rbxassetid://14143584179" -- setting the id of the new animation object
local Orb = Rig.Humanoid:LoadAnimation(anim) -- loading the animation
local Isactive = false
local UIS = game:GetService("UserInputService")

function PlayAnim(Input) -- function for input
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		if Isactive == false then
			Isactive = true
			Orb:Play()
			wait(0.917)
			Isactive = false
		end
	end
end
UIS.InputBegan:Connect(PlayAnim) -- changed because input began will already return the input object to the connected function

i hope this works for u

1 Like

This is my new code:

local Rig = workspace.TemplateR6
local anim = Instance.new("Animation")
local Rstor = game:GetService("ReplicatedStorage")
local Orb = Rig.Humanoid:LoadAnimation(anim)
local Isactive = false
local UIS = game:GetService("UserInputService")
anim.AnimationId = Rstor.Animations.OrbFire

function PlayAnim()
	if UIS.UserInputType == Enum.UserInputType.MouseButton1 then
		if Isactive == false then
		Isactive = true
		Orb:Play()
		wait(0.917)
		Isactive = false
		end

	end
end
UIS.InputBegan:Connect(PlayAnim)

its still not working for some reason
no errors or anything.

local Rig = workspace.TemplateR6
local anim = Instance.new("Animation")
local Rstor = game:GetService("ReplicatedStorage")
local Orb = Rig.Humanoid:LoadAnimation(anim)
local Isactive = false
local UIS = game:GetService("UserInputService")
anim.AnimationId = Rstor.Animations.OrbFire

function PlayAnim(input, gp)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if Isactive == false then
			Isactive = true
			Orb:Play()
			wait(0.917)
			Isactive = false
		end
	end
end

UIS.InputBegan:Connect(PlayAnim)

Use the input param rather than the service for input validation

Its still not working.
The function itself isnt even playing so i assume its a problem with detecting a leftclick

It’s cuz you set the animation id after loading it into the humanoid. Try this:

local Rig = workspace.TemplateR6
local anim = Instance.new("Animation")
anim.AnimationId = Rstor.Animations.OrbFire
local Rstor = game:GetService("ReplicatedStorage")
local Orb = Rig.Humanoid:LoadAnimation(anim)
local Isactive = false
local UIS = game:GetService("UserInputService")

function PlayAnim(input, gp)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if Isactive == false then
			Isactive = true
			Orb:Play()
			wait(0.917)
			Isactive = false
		end
	end
end

UIS.InputBegan:Connect(PlayAnim)

still nothing.
maybe its something with referencing the rig?
Or wait.
could it be trying to detect a click from the rig?
Is that possible?
Actually nvm. the problem was that it wasnt a localscript. lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.