How to make it so that if you hold mouse button it plays an animation

i dont know how to start, btw i have already researched how to do this, but i want it to happen on the server

1 Like

Then maybe try using remote event

how would i stop the remote event too? like for example when the player stops holding the mouse

you can make second remote event for example, that would stop the animation

how would i precisely do that?

local userInputService = game:GetService("UserInputService")

userInputService.InputBegan:Connect(function(input, gameEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		--do event one
	end
end)

userInputService.InputEnded:Connect(function(input, gameEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		--do event two
	end
end)

Here is example how you could do it

1 Like

i tried this

local userInputService = game:GetService("UserInputService")

userInputService.InputBegan:Connect(function(input, gameEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		game:GetService("ReplicatedStorage").Events:WaitForChild("Goober"):FireServer()
	end
end)

userInputService.InputEnded:Connect(function(input, gameEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		game:GetService("ReplicatedStorage").Events:WaitForChild("GooberEnd"):FireServer()
	end
end)

and events handler

game:GetService("ReplicatedStorage").Events:WaitForChild("Goober").OnServerEvent:Connect(function(plr)
	local anim = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script.Goober)
	anim:Play()
	
	game:GetService("ReplicatedStorage").Events:WaitForChild("Goober").OnServerEvent:Connect(function(plr)
		anim:Stop()
	end)
end)
1 Like
local anim

game:GetService("ReplicatedStorage").Events:WaitForChild("Goober").OnServerEvent:Connect(function(plr)
	anim = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script.Goober)	
	anim:Play()
end)

game:GetService("ReplicatedStorage").Events:WaitForChild("GooberEnd").OnServerEvent:Connect(function(plr)
	anim:Stop()
end)

try this as event handler

It works, but i wanted to play a tween but it looks it plays the final destination instantly. look!

local anim
local canRemove = true

game:GetService("ReplicatedStorage").Events:WaitForChild("Goober").OnServerEvent:Connect(function(plr)
	anim = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script.Goober)	
	anim:Play()
	plr.PlayerGui.BarLol.bar.Visible = true
	plr.PlayerGui.BarLol.fire.Visible = true
	plr.PlayerGui.BarLol.bar.progress.Position = UDim2.new(0.706, 0,0.92, 0)
	
	plr.PlayerGui.BarLol.bar.progress:TweenPosition(
		UDim2.new(0.706, 0,0.2, 0), -- Position
		Enum.EasingDirection.Out, -- I set this to In
		Enum.EasingStyle.Linear, -- I set this to Elastic
		5, -- I set it to 5 for a long tween
		true -- I set it just incase there is another tween happening
	)
	
	anim:GetMarkerReachedSignal("booger"):Connect(function()
		plr.PlayerGui.BarLol.bar.Visible = false
		plr.PlayerGui.BarLol.fire.Visible = false
		canRemove = false
		wait(0.45)
		canRemove = true
	end)
	
end)

game:GetService("ReplicatedStorage").Events:WaitForChild("GooberEnd").OnServerEvent:Connect(function(plr)
	if canRemove == true then
		plr.PlayerGui.BarLol.bar.progress.Position = UDim2.new(0.706, 0,0.92, 0)
		plr.PlayerGui.BarLol.bar.Visible = false
		plr.PlayerGui.BarLol.fire.Visible = false
		anim:Stop()
	end
end)