The Issue Is If The Player Dies It Index nil For Every Value
I Couldn’t Understand the problem Soo If Anyone Knows How To Fix It Or Has Another Way To Do It I Would Appreciate it
this is the Module Script
local t = {}
for i, c in pairs(workspace:GetChildren()) do
local h = c:FindFirstChild("Humanoid")
if h then
if h.Parent.Parent ~= workspace.Npc then
t[c] = {
Stun = false,
Attack = false,
Block = false,
PerfectBlock = false,
Dash = false,
cd = false,
cd1 = false,
cd2 = false,
Katana = false,
}
end
end
end
workspace.ChildAdded:Connect(function(c)
local h = c:WaitForChild("Humanoid")
if h then
t[c] = {
Stun = false,
Attack = false,
Block = false,
PerfectBlock = false,
Dash = false,
cd = false,
cd1 = false,
cd2 = false,
Katana = false,
}
end
end)
workspace.ChildRemoved:Connect(function(c)
local h = c:FindFirstChild("Humanoid")
if h then
t[c.Name] = nil
end
end)
return t
And The Script That Uses The Value Is In StarterCharacterScripts + It’s A Client Script.
local t = {}
for i, c in pairs(workspace:GetChildren()) do
local h = c:FindFirstChild("Humanoid")
if h then
if c.Parent ~= workspace.Npc then
t[c.Name] = {
Stun = false,
Attack = false,
Block = false,
PerfectBlock = false,
Dash = false,
cd = false,
cd1 = false,
cd2 = false,
Katana = false,
}
end
end
end
workspace.ChildAdded:Connect(function(c)
local h = c:WaitForChild("Humanoid")
if h then
t[c.Name] = {
Stun = false,
Attack = false,
Block = false,
PerfectBlock = false,
Dash = false,
cd = false,
cd1 = false,
cd2 = false,
Katana = false,
}
end
end)
workspace.ChildRemoved:Connect(function(c)
local h = c:FindFirstChild("Humanoid")
if h then
t[c.Name] = nil
end
end)
return t
Edit:
The key you were setting to nil was c.Name (string) which is different from what the keys actually are which is model instances. The keys must be the same when setting them and deleting them…
Since the key changes when the character is added and removed, it must be referenced every time the function is called. Rather than using PlayerValue[c.Name] every time, you can set it to a variable inside the UserInputService event function and use that… e.g:
function(key, istyping)
local var = PlayerValue[c.Name]
…var.cd…