#problem with trying to use attributes for math

32 messages · Page 1 of 1 (latest)

tame cypress
#

basically im trying to make a fighting game with multiple abilities. these different abilites would impact the stats of each player depending what one they had. becuase of this i decided to make an attribute for damage get created on a player so i can change it easily but when i try to take away the damage attribute, it gives the error "attempt to perform arithmetic (sub) on number and nil". can you just not do maths on a attribute, and if so how would i go about making a system where i can change the damage when you switch abilities? i can send the code if its required.

foggy tiger
#

send code

tame cypress
#

alright, give me a sec

#

i create the attribute in a different script this this line of code :
player:SetAttribute("damage", 10)
but the rest is in a different script located bellow

game.ReplicatedStorage.Remote.activatePower.OnServerEvent:Connect(function(player)

    char = player.Character
    char.Head.Attachment.rightFire.Enabled = true
    char.Head.Attachment2.leftFire.Enabled = true
    char.Head.BrickColor = BrickColor.new("Dark stone grey")
    char.Torso.BrickColor = BrickColor.new("Dark stone grey")
    char["Right Arm"].BrickColor = BrickColor.new("Dark stone grey")
    char["Left Arm"].BrickColor = BrickColor.new("Dark stone grey")
    char["Right Leg"].BrickColor = BrickColor.new("Dark stone grey")
    char["Left Leg"].BrickColor = BrickColor.new("Dark stone grey")
    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth * 2
    char.Humanoid.Health = char.Humanoid.Health * 2
    player:SetAttribute("damage", player:GetAttribute("damage") * 2)
end)

game.ReplicatedStorage.Remote.deactivatePower.OnServerEvent:Connect(function(player)
    char.Head.Attachment.rightFire.Enabled = false
    char.Head.Attachment2.leftFire.Enabled = false
    char.Head.BrickColor = BrickColor.new("Medium stone grey")
    char.Torso.BrickColor = BrickColor.new("Dark stone grey")
    char["Right Arm"].BrickColor = BrickColor.new("Medium stone grey")
    char["Left Arm"].BrickColor = BrickColor.new("Medium stone grey")
    char["Right Leg"].BrickColor = BrickColor.new("Medium stone grey")
    char["Left Leg"].BrickColor = BrickColor.new("Medium stone grey")
    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth / 2
    char.Humanoid.Health = char.Humanoid.Health / 2
    player:SetAttribute("damage", player:GetAttribute("damage") * 2)
end)
#

everything worked until i added the setAttribute stuff

foggy tiger
#

player:GetAttribute("damage").Value ?

tame cypress
#

oh damn, that would make sense ;-; let me try it rq

#

nah it didnt work, "attempt to index nil with 'Value'"

foggy tiger
#

hmmm

#

print(player:GetAttribute("damage")) for me?

tame cypress
#

im already doing that in the other script, i set a variable named damage = player:GetAtrribute("damage") and then printed the variable and then it prints 10 (the base damage i set) so the variable is being made properly

timid micaBOT
#

studio** You are now Level 1! **studio

foggy tiger
#

HMMM

#

idk

tame cypress
#

;-; rip

tame cypress
# foggy tiger idk

do you know another way i could have the same affect of being able to change a individual players damage via script?

tame cypress
#

solved it dw

foggy tiger
tame cypress
# foggy tiger wut wuz the solution?

turns out you were right and even though it printed the damage when the game started, when i actived the ability for some reason damage got set to nil, so now the script checks if the damage = nil, and then sets it equal to 10 if it is

foggy tiger
#

ok

cunning gulch
tame cypress
cunning gulch
tame cypress
dense socket
#

If you set an attribute on client, server won't see it

tame cypress
dense socket
#

Show the script which raises the error

tame cypress
#

oh i already fixed it sorry, thanks anyway

dense socket
#

Ok good luck

tame cypress
#

mb i forgot to add the tag

cunning gulch