The Ability Keybind breaks when the character dies

What’s the issues?
It was perfectly fine until my script broke when my character died and respawned. Now, it seems I can’t use the moves. I’ve tried fixing this many times, but nothing works. My only hope is the DevForum.


I was pressing so hard in the video.

Server

ocal ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local sendkey = ReplicatedStorage:WaitForChild("SendKeys")
local getchar = ReplicatedStorage:WaitForChild("GetChar")
local bindFunction = ReplicatedStorage:WaitForChild("BindFunction")
local skillsUtils = ReplicatedStorage:WaitForChild("SkillUtils")
local charData = skillsUtils:WaitForChild("CharacterData")

local debounces = {}

local function HandleCharacterAdded(player, character)
	character:SetAttribute("Character", "Sukuna")
end

local function HandleCharacterRemoved(player)
	debounces[player] = nil
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		HandleCharacterAdded(player, character)
	end)
	player.CharacterRemoving:Connect(function()
		HandleCharacterRemoved(player)
	end)
end)

sendkey.OnServerEvent:Connect(function(player, input)
	local character = player.Character or player.CharacterAdded:Wait()
	local selected = character:GetAttribute("Character")
	if debounces[player] and debounces[player][input] then return end
	debounces[player] = debounces[player] or {}
	debounces[player][input] = true

	local hotbox = player.PlayerGui:WaitForChild("Hotbox")

	for _, child in pairs(charData:GetChildren()) do
		if selected == child.Name then
			local requireChar = require(child)
			for _, abilityData in pairs(requireChar) do
				if selected and input then
					local characterFolder = script:FindFirstChild(selected)
					if characterFolder then
						local ability = characterFolder:FindFirstChild(input)
						if ability and abilityData.Key == input then
							local abilityInstance = require(ability).new(player)
							local cooldown = hotbox:WaitForChild(input).Cooldown
							if cooldown and not cooldown.Visible then
								local startSize = cooldown.Size
								local endSize = UDim2.new(0, 61, 0, -1)
								cooldown.Size = UDim2.new(0, 61, 0, 60)
								cooldown.Visible = true
								local tweenInfo = TweenInfo.new(abilityData.Cooldown, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
								local tween = TweenService:Create(cooldown, tweenInfo, { Size = endSize })
								tween:Play()
								abilityInstance:Play()
								tween.Completed:Wait()
								local resetTween = TweenService:Create(cooldown, tweenInfo, { Size = startSize })
								resetTween:Play()
								cooldown.Visible = false
							end
						end
					end
				end
			end
		end
	end
	debounces[player][input] = nil
end)

getchar.OnServerEvent:Connect(function(player, name)
	local hotbox = player.PlayerGui:WaitForChild("Hotbox")
	local bar = player.PlayerGui:WaitForChild("AwakeningBar")
	local character = player.Character or player.CharacterAdded:Wait()
	if not character then
		warn("Character not found for player:", player.Name)
		return
	end

	character:SetAttribute("Character", name)

	local characterFolder = script:FindFirstChild(name)

	local availableModules = {}
	for _, child in pairs(characterFolder:GetChildren()) do
		if child:IsA("ModuleScript") then
			table.insert(availableModules, child.Name)
		end
	end

	bindFunction:InvokeClient(player, availableModules)

	for _, child in pairs(charData:GetChildren()) do
		if child:IsA("ModuleScript") and child.Name == name then
			local requireChar = require(child)
			for _, abilityData in pairs(requireChar) do
				local hotboxChar = hotbox:WaitForChild(abilityData.Key)
				hotboxChar.SkillName.Text = abilityData.Name

				if requireChar["Awakening"] then
					local Charbar = bar:WaitForChild("Awakening")
					Charbar.Text = requireChar["Awakening"]
					Charbar.TextLabel.Text = requireChar["Awakening"]
				end
			end
		end
	end
end)

– Client

local rp = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local hotbox = player:WaitForChild("PlayerGui"):WaitForChild("Hotbox")

local sendkey = rp:WaitForChild("SendKeys")
local bindFunction = rp:WaitForChild("BindFunction")

local function HandleInput(input, processed)
	if processed then return end

	local char = player.Character or player.CharacterAdded:Wait()
	if not char then return end

	for _, v in pairs(hotbox:GetChildren()) do
		if v:IsA("Frame") then
			if input.KeyCode == Enum.KeyCode[v.Name] then
				sendkey:FireServer(v.Name)
			end
		end
	end
end

uis.InputBegan:Connect(HandleInput)

bindFunction.OnClientInvoke = function(availableModules)
	for _, v in pairs(hotbox:GetChildren()) do
		if v:IsA("Frame") then
			v.Visible = table.find(availableModules, v.Name) ~= nil
		end
	end

	local spacing = 10
	local totalWidth = 0
	local visibleButtons = {}

	for _, v in pairs(hotbox:GetChildren()) do
		if v:IsA("Frame") then
			totalWidth = totalWidth + v.Size.X.Offset + spacing
			table.insert(visibleButtons,1,v)
		end
	end

	totalWidth = totalWidth - spacing 
	local hotboxWidth = hotbox.AbsoluteSize.X
	local startX = (hotboxWidth - totalWidth) / 2.05

	for _, v in pairs(visibleButtons) do
		v.Position = UDim2.new(0, startX, v.Position.Y.Scale, v.Position.Y.Offset)
		startX = startX + v.Size.X.Offset + spacing
	end
end

Let me know if i did silly mistakes!!

nevermind fixed, i move the client script to startercharacter.

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