I want to make it so that my dab animation not necessarily keeps playing over and over again but just stays in the dab position if the mouse button1 is held. I have used different topics like @SirMing and others, but I couldn’t get it to work. I know that I have to use user input service to do this, but nothing works. What is wrong here?
local player = game.Players.LocalPlayer
local userinputservice = game:GetService("UserInputService")
local function mousedown(inputtype)
for i, mousebutton in pairs(userinputservice:GetMouseButtonsPressed()) do
if mousebutton.UserInputType == inputtype then
local loaddab = player.Character.Humanoid:LoadAnimation(script.Parent.DabAnimation)
loaddab:Play()
print("Played")
return true
end
end
return false
end
held = mousedown(Enum.UserInputType.MouseButton1)
Why not use an animation which is just the position looped?
You could play this at the end of the animation (you can connect to that with Stopped) or alternatively play it at a animation event (see the ‘Animation Events’ section in this tutorial). Of course, the AnimTrack can have Stop called upon it when the mouse button is lifted.
local player = game.Players.LocalPlayer
local userinputservice = game:GetService("UserInputService")
local loaddab = player.Character.Humanoid:LoadAnimation(script.Parent.DabAnimation)
local function mousedown(inputtype)
for i, mousebutton in pairs(userinputservice:GetMouseButtonsPressed()) do
if mousebutton.UserInputType == inputtype then
if loaddab.IsPlaying == false then
loaddab:Play()
end
print("Played")
return true
end
end
return false
if loaddab.IsPlaying == true then
loaddab:Stop() -- Stop the animation when you are not holding mouse
end
end
held = mousedown(Enum.UserInputType.MouseButton1)
local player = game.Players.LocalPlayer
local userinputservice = game:GetService("UserInputService")
local loaddab = player.Character.Humanoid:LoadAnimation(script.Parent.DabAnimation)
local function mousedown(inputtype)
for i, mousebutton in pairs(userinputservice:GetMouseButtonsPressed()) do
if mousebutton.UserInputType == inputtype then
if loaddab.IsPlaying == false then
loaddab:Play()
end
print("Played")
return true
end
end
if loaddab.IsPlaying == true then
loaddab:Stop() -- Stop the animation when you are not holding mouse
end
return false
end
held = mousedown(Enum.UserInputType.MouseButton1)
local player = game.Players.LocalPlayer
local userinputservice = game:GetService("UserInputService")
while player.Character == nil do wait() end
local loaddab = player.Character:WaitForChild("Humanoid"):LoadAnimation(script.Parent:WaitForChild("DabAnimation"))
local function mousedown(inputtype)
for i, mousebutton in pairs(userinputservice:GetMouseButtonsPressed()) do
if mousebutton.UserInputType == inputtype then
if loaddab.IsPlaying == false then
loaddab:Play()
end
print("Played")
return true
end
end
if loaddab.IsPlaying == true then
loaddab:Stop() -- Stop the animation when you are not holding mouse
end
return false
end
held = mousedown(Enum.UserInputType.MouseButton1)
This code when placed inside a LocalScript in Tool
-- LocalScript
local tool = script.Parent
local uis = game:GetService("UserInputService")
local mouseDown = false
local movePlay = true
tool.Equipped:Connect(function(mouse)
local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
local move = humanoid:LoadAnimation(script:WaitForChild("Move"))
mouse.Button1Up:Connect(function()
mouseDown = false
end)
mouse.Button1Down:Connect(function()
uis.InputBegan:Connect(function(inp, gpe)
if inp.UserInputType == Enum.UserInputType.MouseButton1 and not gpe then
mouseDown = true
while mouseDown do
wait(0.04)
if movePlay then
move:Play()
movePlay = false
end
end
end
end)
end)
humanoid.AnimationPlayed:Connect(function(animationTrack)
if animationTrack == move then
animationTrack.Stopped:wait()
movePlay = true
end
end)
end)
The animation continues if the player presses and holds the mouse button 1