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.
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
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)