How do I make the value in an attribute increase by one?

Idk if this is some easy stuff that im just simply to dumb to figure out, but how would I go about increasing the value in an attribute by one?


COMBAT_REMOTE.OnServerEvent:Connect(function(player)
	local character = player.Character
	local Torso = character:WaitForChild("HumanoidRootPart")
	local Combo = player:SetAttributeAttribute("Combo", 1) 
	local function genhitbox()
		local hitbox = game.ReplicatedStorage.Hitbox:Clone()
		hitbox.Parent = character
		hitbox.CFrame = Torso.CFrame*CFrame.new(0,0,-3.5)
		hitbox.CanCollide = false
		hitbox.Anchored = true
		wait(0.3)
		hitbox:Destroy()
	end
	if player:GetAttributeAttribute("Stunned") == nil and player:GetAttribute("Blocking") == nil then
		player:SetAttribute("Combo", )
	end

end)

im trying to make the combo go up 1 everytime the event is fired and the attributes are nil. But it never works,
I’ve tried to do
“Combo = 1”
and then increase it using that,
but when one person hits and another person hits, person B’s combo is 2.

if you need video context just lmk.

1 Like
player:SetAttribute("Combo", player:GetAttribute("Combo") + 1)

Nvm I don’t think this would work since your title (which I was answering) doesn’t really match the post.

1 Like

Before you set the attribute you can use local var = object:GetAttribute(“Combo”) + 1

I can’t remember if it’ll error because the attribute may not be numeral, if it errors you can make it a numeral value by

tonumber()

Like this
local var = tonumber(object:GetAttribute(“Combo”)) + 1

Then set the attribute to the new var

(sorry hard to be more detailed on my mobile)

1 Like

increase by 1

local combo = player:GetAttribute("Combo") or 0
player:SetAttribute("Combo", combo + 1)

“im trying to set the combo from 1 to 2”
or just

player:SetAttribute("Combo", 2)

Also your script says: player:GetAttributeAttribute(“Stunned”)==nil
It Should be: player:GetAttribute(“Stunned”)==nil

if player:GetAttribute("Stunned")==nil and
	player:GetAttribute("Blocking")==nil then
	player:SetAttribute("Combo", 2)
end
1 Like
local maxNumber = 2 -- set this to what you want the highest number to be
local currentComboNumber = player:GetAttribute("Combo")

if currentComboNumber >= maxNumber then
    player:SetAttribute("Combo", 1)
else
    player:SetAttribute("Combo", player:GetAttribute("Combo") + 1)
end

Not at my PC rn but to add upon my question:
Some left out stuff; I want it to increase by 1 everytime the event is fired.

(Note: I havent gotten the chance to see if any of your offered solutions work so they may help)

21:53:49.188 ServerScriptService.Combat Server:19: attempt to perform arithmetic (add) on nil and number - Server - Combat Server:19

I suppose you were trying to do player:GetAttribute("Combo") + 1 while it is nil. You should do something like that:

-- other code
else
    if player:GetAttribute("Combo") == nil then player:SetAttribute("Combo", 0) end -- if nil, set to 0
    local val = player:GetAttribute("Combo") + 1
    player:SetAttribute("Combo", val)
end

this helps but i found another issue,
im using a remote on a server script to find the player.
and everytime i fire it, it sets the player back to combo value 0. i tried to put the actual set combo on a different script but it didn’t work. Here’s the script:

local COMBAT_REMOTE = game.ReplicatedStorage.COMBAT_REMOTE

COMBAT_REMOTE.OnServerEvent:Connect(function(player)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local Torso = character:WaitForChild("HumanoidRootPart")
        local Combo = humanoid:SetAttribute("Combo", 0)
	local val = humanoid:GetAttribute("Combo")
	local function genhitbox()
		local hitbox = game.ReplicatedStorage.Hitbox:Clone()
		hitbox.Parent = character
		hitbox.CFrame = Torso.CFrame*CFrame.new(0,0,-3.5)
		hitbox.CanCollide = false
		hitbox.Anchored = true
		wait(0.3)
		hitbox:Destroy()
	end
	humanoid:SetAttribute("Combo", val + 1)
	print(val)
	end)

if it is possible to put this on a local script that would be great. (im relatively new to scripting sorry if this is obvious stuff lol.)

local COMBAT_REMOTE = game.ReplicatedStorage.COMBAT_REMOTE
local Combo = humanoid:SetAttribute("Combo", 0) --/!!/  Default starting value for the attribute, gets set as soon as script is spawned unless in a function, then it will run everytime when the function runs

--/!!/  Note for above you don't even need this line if you set the default value to 0 for the Attribute in the explorer.

COMBAT_REMOTE.OnServerEvent:Connect(function(player)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local Torso = character:WaitForChild("HumanoidRootPart")
	--local Combo = humanoid:SetAttribute("Combo", 0) --/!!/  Moved above function so it doesn't run every time function is ran

	local increasedCombo = humanoid:GetAttribute("Combo") + 1 --/!!/  this gets the current value of the attribute and should increase it by 1
	print(increasedCombo)

	local function genhitbox()
		local hitbox = game.ReplicatedStorage.Hitbox:Clone()
		hitbox.Parent = character
		hitbox.CFrame = Torso.CFrame*CFrame.new(0,0,-3.5)
		hitbox.CanCollide = false
		hitbox.Anchored = true
		wait(0.3)
		hitbox:Destroy()
	end

	humanoid:SetAttribute("Combo", increasedCombo) --/!!/  Here it sets the Attribute to the increasedCombo variable


	end)

If something like attempt to perform arithmetic (add) on string and number appears than you’ll need to do local increasedCombo = tonumber(humanoid:GetAttribute("Combo")) + 1

COMBAT_REMOTE.OnServerEvent:Connect(function(player)
  local character = player.Character
  local Torso = character:WaitForChild("HumanoidRootPart")

  if player:GetAttribute("Stunned") == nil and player:GetAttribute("Blocking") == nil then
    local currentCombo = player:GetAttribute("Combo") or 0
    local newComboValue = currentCombo + 1
    player:SetAttribute("Combo", newComboValue)

    local function genhitbox()
      local hitbox = game.ReplicatedStorage.Hitbox:Clone()
      hitbox.Parent = character
      hitbox.CFrame = Torso.CFrame*CFrame.new(0,0,-3.5)
      hitbox.CanCollide = false
      hitbox.Anchored = true
      wait(0.3)
      hitbox:Destroy()
    end

    genhitbox()
  end
end)

much appreciated bro!, (also sky10) much appreciated. both worked, thank you!

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