I Gave humanoids the percentage attribute and replaced the take damage function with the percentage changed and for some reason it will no longer run
here is the percentage attribute assignment
game.workspace.ChildAdded:Connect(function(child)
if child:FindFirstChild('Humanoid') then
child:SetAttribute('Percentage',0)
end
end)
for _, v in pairs(workspace:GetDescendants()) do
if v:FindFirstChild('Humanoid') then
v:SetAttribute('Percentage',0)
end
end
this seems to work the attribute is apart of the player when the game is run but the new damage function returns me a not so nice error
ServerScriptService.Knockback:6: attempt to perform arithmetic (add) on nil and number
here it is
if data.Action == "m1" then
data.Target.Humanoid:GetAttribute('Percentage' )
data.Target.Humanoid:SetAttribute('Percentage', data.Target.Humanoid:GetAttribute('Percentage') + 2)
For some reason that block of code won’t work
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
I’d add some debug prints and check for nil values.
Attribute Assignment Script:
game.Workspace.ChildAdded:Connect(function(child)
if child:FindFirstChild('Humanoid') then
child:SetAttribute('Percentage', 0)
print("Set Percentage to 0 for: " .. child.Name)
end
end)
for _, v in pairs(workspace:GetDescendants()) do
if v:FindFirstChild('Humanoid') then
v:SetAttribute('Percentage', 0)
print("Set Percentage to 0 for: " .. v.Name)
end
end
Damage Function Script:
if data.Action == "m1" then
local currentPercentage = data.Target.Humanoid:GetAttribute('Percentage')
if currentPercentage == nil then
-- This shouldn't happen if attributes are set correctly
warn("Percentage attribute is nil for: " .. data.Target.Humanoid.Parent.Name)
currentPercentage = 0
data.Target.Humanoid:SetAttribute('Percentage', currentPercentage)
end
data.Target.Humanoid:SetAttribute('Percentage', currentPercentage + 2)
print("Updated Percentage for: " .. data.Target.Humanoid.Parent.Name .. " to " .. (currentPercentage + 2))
end
Looks like you were mixing up the Humanoid and the actual Character object. This should be what you want. (i.e you were setting the Attribute on the wrong object)
Let me know if this fixes your issue? Place.rbxl (106.8 KB)