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.
#problem with trying to use attributes for math
32 messages · Page 1 of 1 (latest)
send code
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
player:GetAttribute("damage").Value ?
oh damn, that would make sense ;-; let me try it rq
nah it didnt work, "attempt to index nil with 'Value'"
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
** You are now Level 1! **
;-; rip
do you know another way i could have the same affect of being able to change a individual players damage via script?
solved it dw
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
ok
If you created the attribute in a local script and tries to handle it on a server script the server cant see the attribute.
oh i see, that makes sense. thanks
Np, little tip next time: on a server script: ```lua
game.Players.PlayerAdded:Connect(function(player)
--do the logic for the player’s starter
end)
oh that makes sense, does the same thing as the local script just on a server one
There's not a single substruction (-) in this script. The error is caused by another script?
If you set an attribute on client, server won't see it
yeah, it came from the damage handler script which both had the same problem, so if i figured one out i could fix the other
Show the script which raises the error
oh i already fixed it sorry, thanks anyway
Ok good luck
mb i forgot to add the tag
always configure the player on the server so everybody can see it.