Dashes doesnt work after 3 uses

So i have this script right here for like 3 dashes and everytime the attribute changes it closes one of the frame, but for some reason i can only use it 3 times, even tho it does regen although not fully i cant reuse it anymore.

i have another script where it subtract one of the dashes if i press e and that works fine but it stops after 3 dashes.

-- Services --
local players = game:GetService("Players")
local rep = game:GetService("ReplicatedStorage")
local ts = game:GetService("TweenService")
local rs = game:GetService("RunService")
local gui = game:GetService("StarterGui")
-- Player Stuff --
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum:Humanoid = char:WaitForChild("Humanoid")

-- Frames --
local frame1 = script.Parent:WaitForChild("Dash 1")
local frame2 = script.Parent:WaitForChild("Dash 2")
local frame3 = script.Parent:WaitForChild("Dash 3")

local dashes = char:GetAttribute("dashes")


char:GetAttributeChangedSignal("dashes"):Connect(function()
	dashes = char:GetAttribute("dashes")
	
	if dashes == 3 then
		frame1.Visible = true
		frame2.Visible = true
		frame3.Visible = true
	elseif dashes == 2 then
		frame1.Visible = false
		frame2.Visible = true
		frame3.Visible = true
	elseif dashes == 1 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = true
	elseif dashes == 0 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = false
	end
end)

char:GetAttributeChangedSignal("dashes"):Connect(function()
	if dashes > 0 and dashes == 3 then
		wait(5)
		
		dashes = dashes + 1
		char:SetAttribute("dashes", dashes)
	end
end)

-- Services --
local players = game:GetService("Players")
local rep = game:GetService("ReplicatedStorage")
local ts = game:GetService("TweenService")
local rs = game:GetService("RunService")
local gui = game:GetService("StarterGui")
-- Player Stuff --
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum:Humanoid = char:WaitForChild("Humanoid")

-- Frames --
local frame1 = script.Parent:WaitForChild("Dash 1")
local frame2 = script.Parent:WaitForChild("Dash 2")
local frame3 = script.Parent:WaitForChild("Dash 3")

local dashes = char:GetAttribute("dashes")

local cd = 0

char:GetAttributeChangedSignal("dashes"):Connect(function()
	dashes = char:GetAttribute("dashes")
	
	if dashes == 3 then
		frame1.Visible = true
		frame2.Visible = true
		frame3.Visible = true
	elseif dashes == 2 then
		frame1.Visible = false
		frame2.Visible = true
		frame3.Visible = true
	elseif dashes == 1 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = true
	elseif dashes == 0 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = false
	end
end)

local function regen()
	if cd == 0 then

	dashes = dashes + 1
	char:SetAttribute("dashes", dashes)
	end
end



char:GetAttributeChangedSignal("dashes"):Connect(function()
	if dashes > 0 and dashes < 3 then
		
		
		regen()
		cd = 5
	else if dashes > 3 then 
			dashes = 3
			char:SetAttribute("dashes", 3)
		end
	end
end)

rs.Heartbeat:Connect(function(deltatime)
	wait(deltatime)
	if cd > 0 and cd < 5 then
	cd = cd - 1
	print(cd)
	end

end)

fixed some stuff now it works but the cooldown doesnt, i want it to reset the cooldown back to 5 every time a dash is use and it counts down, dont know how to do that tho

Create a variable to store cooldown timestamp local timestamp = time()
Every time you dash rewrite with current time (Check if difference in dashes is negative to determine if a dash was used)
Inside your Heartbeat connection, check the difference between time() and timestamp and if it exceeds 5 regen dash and reset timestamp

if (time() - timestamp  >= 5)
   dashes += 1
   cd = time()
end
1 Like

didnt really work and also i didnt understand what you meant

-- Frames --
local frame1 = script.Parent:WaitForChild("Dash 1")
local frame2 = script.Parent:WaitForChild("Dash 2")
local frame3 = script.Parent:WaitForChild("Dash 3")

wait(1)
local dashes = char:GetAttribute("dashes")

local cd = true

local timestamp = time()


local function regen()
	if not cd  then
		if dashes > 3 then dashes = 3 end
		dashes = dashes + 1
		char:SetAttribute("dashes", dashes)
		task.wait(0.1)
		cd = true
	end
end

char:GetAttributeChangedSignal("dashes"):Connect(function()
	dashes = char:GetAttribute("dashes")
	cd = true
	if not cd then return end
	if dashes == 3 then
		frame1.Visible = true
		frame2.Visible = true
		frame3.Visible = true
	elseif dashes == 2 then
		frame1.Visible = false
		frame2.Visible = true
		frame3.Visible = true
		task.wait(5)
		cd = false
		regen()
	elseif dashes == 1 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = true
		task.wait(5)
		cd = false
		regen()
	elseif dashes == 0 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = false
		task.wait(5)
		cd = false
		regen()
	end

	
end)

changed stuff and still doesnt work

Haven’t implemented it anywhere close to how I said, I can’t really explain it any better

you’re setting “dashes” to 3 every regen

LocalScript
--LocalScript in StarterPlayerScripts
local char = script.Parent
local frame1 = script.Parent:WaitForChild("Dash 1")
local frame2 = script.Parent:WaitForChild("Dash 2")
local frame3 = script.Parent:WaitForChild("Dash 3")

local dashes = char:GetAttribute("dashes") or 3

local function updateFrames()
	frame1.Visible = dashes >= 3
	frame2.Visible = dashes >= 2
	frame3.Visible = dashes >= 1
end

updateFrames()

local function regen()
	while dashes < 3 do
		task.wait(5)
		dashes = dashes + 1
		char:SetAttribute("dashes", dashes)
		updateFrames()
	end
end

char:GetAttributeChangedSignal("dashes"):Connect(function()
	dashes = char:GetAttribute("dashes")
	updateFrames()
	if dashes < 3 then
		task.spawn(regen)
	end
end)

Doesnt work and ive tried variations of it already

thats like if it goes over 3 it goes back to 3

-- services --
local uis = game:GetService("UserInputService")
local players = game:GetService("Players")
local rep = game:GetService("ReplicatedStorage")
local ts = game:GetService("TweenService")
local rs = game:GetService("RunService")
local gui = game:GetService("StarterGui")
-- player stuff --

local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
-- Attributes --
wait(1)
-- Gui --
local frame1 = script.Parent:WaitForChild("Dash 1")
local frame2 = script.Parent:WaitForChild("Dash 2")
local frame3 = script.Parent:WaitForChild("Dash 3")

local dashes = char:GetAttribute("dashes")


local function updateFrames()
	dashes = char:GetAttribute("dashes")

	if dashes == 3 then
		frame1.Visible = true
		frame2.Visible = true
		frame3.Visible = true
	elseif dashes == 2 then
		frame1.Visible = false
		frame2.Visible = true
		frame3.Visible = true
	elseif dashes == 1 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = true
	elseif dashes == 0 then
		frame1.Visible = false
		frame2.Visible = false
		frame3.Visible = false
	end
end

updateFrames()

-- Cooldown timestamp for dash regeneration
local timestamp = time()

-- Listen for dash changes
char:GetAttributeChangedSignal("dashes"):Connect(function()
	local oldDashes = dashes
	dashes = char:GetAttribute("dashes")
	updateFrames()
	-- If a dash was used (dashes decreased), update timestamp
	if dashes < oldDashes then
		timestamp = time()
	end
end)

-- Heartbeat loop for dash regeneration
rs.Heartbeat:Connect(function()
	-- Only regenerate if dashes < 3
	if dashes < 3 then
		if time() - timestamp >= 5 then
			dashes = dashes + 1
			char:SetAttribute("dashes", dashes)
			updateFrames()
			timestamp = time()
		end
	end
end)


got it to work, sadly thanks to ai, using with your words

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