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

Yeah hey its me again how can i fix this?

I added a countdown and its not working i have no clue why theres no errors the m1 still works tho


Enabled = true
local combo = 1
local countdowntime = 0
damage = 37
script.Parent.OnServerEvent:Connect(function(player,action,var)
	countdowntime = 0
	
	damage = 37 + player.SkillsFolder.Strength.Value
	if Enabled == false then return end
	local chr = player.Character
	
	if action =="Attack" then
		Enabled = false
		
		
		if combo == 1 then
		local anim = script.Slash1
		local playanimation = chr.Humanoid:LoadAnimation(anim)
			playanimation:Play()
			combo = 2
			else
			local anim = script.Slash2
			local playanimation = chr.Humanoid:LoadAnimation(anim)
			playanimation:Play()
			combo = 1
		end
		for i,v in pairs(workspace:GetChildren()) do
			if v:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Humanoid") then
				if v~= chr then
					if (v.HumanoidRootPart.Position - chr.HumanoidRootPart.Position).magnitude < 7 then
						v.Humanoid:TakeDamage(damage)
					end
				end
			end
		end
		wait(0.8)
		Enabled = true
	end
end)
script.Parent.OnServerEvent:Connect(function()
	repeat 
		wait(0.1) 
		countdowntime = countdowntime + 0.1 
	until  combo == 1
end)
while true do
	wait(0.025)
	if countdowntime > 1 then
		combo = 1
	end
end

2 comments

0

You should not do all this code inside of a server script. If there are more than one player, both players can change the variables and it would get very glitchy.

0

Or just fit it all inside of the function

1 answer

You should just add a countdown timer when reaching 0, it ends the combo. You also need to add a way to reset the timer back when the player attacks again.

Enabled = true
local combo = 1
local countdowntime = 10 -- or any amount of time
damage = 37
script.Parent.OnServerEvent:Connect(function(player,action,var)
    countdowntime = 0

    damage = 37 + player.SkillsFolder.Strength.Value
    if Enabled == false then return end
    local chr = player.Character

    if action =="Attack" then
        Enabled = false
	countdowntime = 10 -- resets the timer when player attacks


        if combo == 1 then
        local anim = script.Slash1
        local playanimation = chr.Humanoid:LoadAnimation(anim)
            playanimation:Play()
            combo = 2
            else
            local anim = script.Slash2
            local playanimation = chr.Humanoid:LoadAnimation(anim)
            playanimation:Play()
            combo = 1
        end
        for i,v in pairs(workspace:GetChildren()) do
            if v:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Humanoid") then
                if v~= chr then
                    if (v.HumanoidRootPart.Position - chr.HumanoidRootPart.Position).magnitude < 7 then
                        v.Humanoid:TakeDamage(damage)
                    end
                end
            end
        end
        wait(0.8)
        Enabled = true
    end
end)
-- replaces function with countdown loop
while true do
	if countdowntime > 0 then
		countdowntime = countdowntime - 0.1 --count down
	end
	if countdowntime <= 0 then
		combo = 1 -- ends the combo when countdown is 0
	end
	wait(0.1)
end

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