Why is my Weapons tool not working?

Im trying to make a Tool that can summon an ability after 3 times it has been activated

Problems

Ability Function never even works.
Debounce also doesn’t seem to work.
AbilityFX Doesn’t Load in.

Questions

Is there a way to fix my cooldown?
How would I make it so the FX Spawn at an accurate area around the field?

Script

local Tool = script.Parent

local Ability1Combo = 0

local RS = game:GetService("ReplicatedStorage")

local AbilityFX2 = RS:WaitForChild("AbilityFX2")

local Debounce = false

Tool.Activated:Connect(function()
	if Debounce == false then
		task.wait(1)
		Ability1Combo = Ability1Combo + 1
	else
		if Debounce ~= false then
			print("Ability 2 Is on Cooldown...")
		end
	end
end)

local function SummonAbility()
	Debounce = true
	print("Ability 2 Has Been Summoned")
	local FXClone = AbilityFX2:Clone()
	FXClone.Parent = workspace
	FXClone.Position = script.Parent.Parent:WaitForChild("HumanoidRootPart").Position + Vector3.new(4,0,3)
	task.wait(30)
	Debounce = false
	Ability1Combo = 0
end


if Ability1Combo == 3 then
	Ability1Combo = 0
	
	task.wait(0.5)

	SummonAbility()
end

while true do
	task.wait(0.5)
	print(Ability1Combo)
end
1 Like

That’s because you never revert the debounce to true, you only set it to false and never set it to true. Debounces should look like this:

local db = false
if not db then
    db = true -- lock the scope so it doesnt run until db is false again
    -- code
    db = false
end

This has something to do with your if statement:

You only let this if statement run once. Put it in a loop to constantly check it.

I don’t think you should add another debounce inside the function as the first couple checks of the debounce can already deal with this.

1 Like

It seems to be working now but, models don’t have position so, how would I move the model in a certain area in the field?

Get the CFrame of the HumanoidRootPart and use it in Model:PivotTo(CFrame).

Can I add an offset to it? and is there a way to check if it is a certain area?

CFrame += CFrame + Vector3.new(offset)

What do you mean by a certain area?

Like if I was to be in an area in a game, like in a box, if I went out, Is there a way to make it so the ability will cancel or be moved into the box?

You then have to do sanity checks on CFrames.

1 Like
  22:52:38.793  Unable to cast Instance to CoordinateFrame  -  Client - Abilitys:27
  22:52:38.793  Stack Begin  -  Studio
  22:52:38.793  Script 'Workspace.NubblyFry.Dandilion Collecter.Abilitys', Line 27 - function SummonAbility  -  Studio - Abilitys:27
  22:52:38.793  Script 'Workspace.NubblyFry.Dandilion Collecter.Abilitys', Line 40  -  Studio - Abilitys:40
  22:52:38.793  Stack End  -  Studio
FXClone.Position = FXClone:PivotTo(script.Parent.Parent:WaitForChild("HumanoidRootPart"))

You’re only referring the HumanoidRootPart part itself, not the CFrame.

Also, sorry if I didn’t say this sooner but, I changed the script a tiny bit.

The issue now is that only the base part will flip over, but the rest of the part won’t.


local function SummonAbility()
	Debounce = true
	print("The Ability Flower Power Has Been Summoned!")
	local FXClone = AbilityFX2:Clone()
	FXClone.Parent = workspace
	FXClone:PivotTo(script.Parent.Parent:WaitForChild("HumanoidRootPart").CFrame)
	FXClone.AbilityFXBASE.CFrame.Rotation = CFrame.Angles(0,0,90)
	task.wait(0.5)
	Ability1Combo = 0
	Debounce = false
end

It happens in this part:

FXClone.AbilityFXBASE.CFrame.Rotation = CFrame.Angles(0,0,90)