- What do you want to achieve? Keep it simple and clear!
I want to animate the player character when clicking the screen. I know I can use UserInputService but it wont be the same since mobile players will click and shoot at the same time.
- What is the issue? Include screenshots / videos if possible!
Tool.Activated is firing once in a while (On Game Play, not game).
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve checked my script grammar and it seems to be fine. I also looked at the devforum and found two topics about this and both I tried and none worked.
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local IdleAnimation = Instance.new("Animation")
IdleAnimation.AnimationId = "rbxassetid://9265061225"
IdleAnimation.Name = "Idle"
IdleAnimation.Parent = Tool
local MainAnimation = Instance.new("Animation")
MainAnimation.AnimationId = "rbxassetid://9265488451"
MainAnimation.Name = "Action"
MainAnimation.Parent = Tool
local isShooting = false
local Animations = {
Idle = nil,
Action = nil
}
-- Grip Positions for Idle and Action Animations
local GripPositions = {
["Idle"] = {
GripForward = Vector3.new(0.115, -0.403, 0.908),
GripPos = Vector3.new(-1.291, -0.317, 0.028),
GripRight = Vector3.new(-0.983, -0.178, 0.045),
GripUp = Vector3.new(-0.143, 0.898, 0.416),
},
["Action"] = {
GripForward = Vector3.new(0.999, 0.004, -0.044),
GripPos = Vector3.new(-0.95, -0.316, 0.013),
GripRight = Vector3.new(0.043, 0.015, 0.999),
GripUp = Vector3.new(-0.005, 1, -0.014),
}
}
function changeGripPositions(typeOfAnimation)
for gripType, gripVector in pairs(GripPositions[typeOfAnimation]) do
Tool[gripType] = gripVector
end
end
Tool.Equipped:Connect(function()
if not Animations["Idle"] then
local Animator = humanoid:FindFirstChild("Animator")
if Animator then
-- Load Idle Animation and Play it
Animations["Idle"] = Animator:LoadAnimation(IdleAnimation)
Animations["Idle"]:Play()
changeGripPositions("Idle")
-- Load Shooting Animation
Animations["Action"] = Animator:LoadAnimation(MainAnimation)
end
end
end)
Tool.Unequipped:Connect(function()
if Animations["Idle"] then
Animations["Idle"]:Stop()
Animations["Idle"] = nil
changeGripPositions("Idle")
end
if Animations["Action"] then
Animations["Action"]:Stop()
Animations["Action"] = nil
end
end)
-- When the player clicks then shooting is turned on
Tool.Activated:Connect(function()
print(1)
isShooting = true
Animations["Idle"]:Stop()
Animations["Action"]:Play()
changeGripPositions("Idle")
print(isShooting)
end)
-- When the player stoping holding click or clicking shooting turns off
Tool.Deactivated:Connect(function()
print(2)
isShooting = false
Animations["Action"]:Stop()
wait(0.2)
Animations["Idle"]:Play()
changeGripPositions("Action")
print(isShooting)
end)
Thanks,
Indelton