How can I make this a tool?

print("I exist")

local cas = game:GetService("ContextActionService")
local rs = game:GetService("ReplicatedStorage")

local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")

local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")

local leftPunch = animator:LoadAnimation(script:WaitForChild("LeftPunch"))
local rightPunch = animator:LoadAnimation(script:WaitForChild("RightPunch"))

local currentPunch = 0
local lastPunch = 0

local debounce = false

local function punch()
	print("punched")
	if debounce then return end
	if tick() - lastPunch > 5 then
		currentPunch = 0
	end

	debounce = true
	if currentPunch == 0 then
		rightPunch:Play()
		hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3)
		task.wait(0.6)
		debounce = false
	elseif currentPunch == 1 then
		leftPunch:Play()
		hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3)
		task.wait(0.6)
		debounce = false
	elseif currentPunch == 2 then
		rightPunch:Play()
		hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3)
		task.wait(0.8)
		debounce = false
	end
	if currentPunch == 2 then
		currentPunch = 0
	else
		currentPunch += 1
	end
	lastPunch = tick()
end

function onEquipped()
	print("equip")
	cas:BindAction("Punch", punch, true, Enum.UserInputType.MouseButton1)
end

function Unequipped()
	print("unequip")
	cas:UnbindAction("Punch")
end

script.Parent.Equipped:Connect(onEquipped)
script.Parent.Unequipped:Connect(Unequipped)

maybe some other people can help if they see this post

When you do script.Parent.Equ… does the word Equipped auto fill when you are typing it?

what do you mean? what is auto fill?

yes

script.Parent.Equipped:Connect(onEquipped)
script.Parent.Unequipped:Connect(Unequipped)
1 Like

Update: after the player dies or resets this pops up in the output:

  10:36:27.261  I exist  -  Client - LocalScript:1
  10:37:01.918  I exist  -  Client - LocalScript:1
  10:37:01.966  Cannot load the AnimationClipProvider Service.  -  Client - LocalScript:14
  10:37:01.967  Stack Begin  -  Studio
  10:37:01.967  Script 'Players.Player2.Backpack.Punch.LocalScript', Line 14  -  Studio - LocalScript:14
  10:37:01.967  Stack End  -  Studio
1 Like

What’s line 14? Just send that line.

I’m assuming it’s

local leftPunch = animator:LoadAnimation(script:WaitForChild("LeftPunch"))
2 Likes

Delete the ContextActionService:BindAction line. Move the script into a tool, and replace it with
tool.Activated:Connect(Punch)

You no longer need actionnane or inputstate / their checks you did not do this so your fine. Just do the above

can it still be a local script for tool.Activated?

Yes, your localscript can access every event of it’s parented tool so doing it on a localscript is deal for obvious reasons.
Roblox Documentation: Tool | Documentation - Roblox Creator Hub

However, about the animation issue. I’ve noticed a lot of other developers have been experiencing that issue aswell, so I believe your code is correct and it’s Roblox’s fault.

I believe there is nothing you can do about it but wait until it’s fixed.

1 Like

So it should be working when that bug is fixed by roblox?

(i also added the tool.Activated)

I assume so. But I don’t know if they will fix or not.

Yes. Do what I said and it should work perfectly.

1 Like

Dammit, well I’ll eat grass if they do, this AnimationClipService thing has been up for months, truly annoying :I

I know a fix to that. If you’re checking for
plr.Character or plr.CharacterAdded:Wait()

just use plr.CharacterAdded:Wait() alone

kind of hacky but itll work (ish) better

this is my script now but it still doesnt work (the animatin bug doesnt appear anymore)

print("I exist")

local cas = game:GetService("ContextActionService")
local rs = game:GetService("ReplicatedStorage")

local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")

local plr = game.Players.LocalPlayer
local character = plr.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")

local leftPunch = animator:LoadAnimation(script:WaitForChild("LeftPunch"))
local rightPunch = animator:LoadAnimation(script:WaitForChild("RightPunch"))

local currentPunch = 0
local lastPunch = 0

local debounce = false

local function punch()
	print("punched")
	if debounce then return end
	if tick() - lastPunch > 5 then
		currentPunch = 0
	end

	debounce = true
	if currentPunch == 0 then
		rightPunch:Play()
		hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3)
		task.wait(0.6)
		debounce = false
	elseif currentPunch == 1 then
		leftPunch:Play()
		hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3)
		task.wait(0.6)
		debounce = false
	elseif currentPunch == 2 then
		rightPunch:Play()
		hitboxEvent:FireServer(Vector3.new(3,3,3), Vector3.new(2), 10, 0.3)
		task.wait(0.8)
		debounce = false
	end
	if currentPunch == 2 then
		currentPunch = 0
	else
		currentPunch += 1
	end
	lastPunch = tick()
end

script.Parent.Activated:Connect(punch)

Turn off RequiresHandle in your tool.

2 Likes

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