Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't my script change the value of my combo?

--Variables
local Player = game.Players.LocalPlayer
local Char = Player.Character
local Tool = script.Parent
local SwingSound = Tool:WaitForChild("HitSound")
local CanAttack = Tool:WaitForChild("CanAttack")
local Remote = game.ReplicatedStorage:WaitForChild("Combat")
local HitBox = Tool:WaitForChild("HitBox")

--Tool Equip Function
Tool.Equipped:Connect(function()
	local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
	Idle:Play()
end)

--Tool Activated Function


Tool.Activated:Connect(function()
	local Combo = 1
	CanAttack.Value = true
	if Combo == 1 then
		local Combo1Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Combo1)
		SwingSound:Play()
		Combo1Anim:Play()
		Combo = 2
	elseif Combo == 2 then
		local Combo2Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Combo2)
		SwingSound:Play()
		Combo2Anim:Play()
		Combo = 3
	elseif Combo == 3 then
		local Combo2Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Combo3)
		SwingSound:Play()
		Combo3Anim:Play()
		Combo = 4
	elseif Combo == 4 then
		local Combo2Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Combo4)
		SwingSound:Play()
		Combo4Anim:Play()
		Combo = 5
	elseif Combo == 5 then
		local Combo2Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Combo5)
		SwingSound:Play()
		Combo5Anim:Play()
		Combo = 6
	elseif Combo == 6 then
		local Combo2Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Combo6)
		SwingSound:Play()
		Combo6Anim:Play()
		Combo = 1
	end
end)

--Tool Unequip Function
Tool.Unequipped:Connect(function()
local Hum = Char:WaitForChild("Humanoid")
	for _,anim in pairs(Hum:GetPlayingAnimationTracks()) do 
		anim:Stop()
	end
end)

Above is my local script for an attack tool. I have found 3 issues.

  1. In my script I have specified at the end of each if/ elseif it changes the value of the combo, so when the tool is activated again, it will play a different animation in the combo chain. This doesn't seem to be working however, I tested and the combo value stays at 1.
  2. I don't know how to add a cooldown for the attacks, so I can just spam click the attack and it will play on rapid fire.
  3. When my tool equips it plays a looping animation to show its equipped, and there's a function to stop all animations when the tool is unequipped. This also doesn't seem to be working.

I'm very new to scripting and don't have that much understanding so I would appreciate if someone could fix my script or tell me how to fix it. Thanks!

2 answers

This may or may not work, but I create a numbervalue instead of just the variable. The variable sometimes doesn't change for complicated reasons, so I'll just show the numbervalue way.

local comboValue = Instance.new("NumberValue") -- Create the number value
comboValue.Value = 0 -- You have to put value each time after it or it'll look for the object

Replace every time you originally mentioned combo with comboValue.Value instead.

1 comment

0

Thanks for the help but it doesn't seem to work ):

I've now found the answer, in my script, I put the combo value in the function, meaning every time the function was executed, the combo would be 1.

This discussion is preserved as it was. New answers, comments, and votes are closed.