I'm trying to add two different variables together but nothing works out.
Here's the script. Look at lines 16-20
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player -- Display an 'IntValue' on leaderboard local Power = Instance.new("IntValue") Power.Name = "Power" Power.Value = 150 Power.Parent = leaderstats player.CharacterAdded:connect(function(Character) local Humanoid = Character:WaitForChild("Humanoid") Humanoid.Died:connect(function() if Humanoid:FindFirstChild("creator") ~= nil then local Killer = Humanoid.creator.Value local killerpoints = Killer.leaderstats.Power.Value local deadpoints = Power.Value killerpoints = killerpoints + deadpoints -- Add dead players points to killer's points end Power.Value = 0 --Set dead player's points to zero end) end)
A mistake that you are making is setting a variable to the value
of a variable, rather than making a reference
to the variable, and using the Value property of it after that.
Ex:
local numval = Number.Value--x numval = numval + 2 print(Number.Value,numval,numval == Number.Value) --x, x+2, false
Ex2:
local num = Number--value is x num.Value = num.Value + 5 print(num.Value)--x+5
Why is this? Well, it is because you are merely creating a number equivalent to the value of the Power of Both players, rather than referencing them. therefore, if you modify this new variable, the originals remain unchanged.
What you should do is remove the Value getter on lines 16 and 17, then add them on line 18 like such:
local killerpoints = Killer.leaderstats.Power local deadpoints = Power killerpoints.Value = killerpoints.Value + deadpoints.Value
small note:the deadpoints variable however, can remain unchanged, as no change is happening to it
Hopefully this helped! Besure to accept if it did!
Its at line 17. Since you're defining it as the actual value rather then just doing the instance and then apply its value, you're only adding numbers but not the actual value.
Example:
If the enemy killerpoints is 50 and the variable you made is still like that then its just 50, and since the deadpoints variable is worth something like 70 then its just 120, and its not going to add anything to killerpoints.
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player -- Display an 'IntValue' on leaderboard local Power = Instance.new("IntValue") Power.Name = "Power" Power.Value = 150 Power.Parent = leaderstats player.CharacterAdded:connect(function(Character) local Humanoid = Character:WaitForChild("Humanoid") Humanoid.Died:connect(function() if Humanoid:FindFirstChild("creator") ~= nil then local Killer = Humanoid.creator.Value local killerpoints = Killer.leaderstats.Power local deadpoints = Power.Value killerpoints.Value = killerpoints.Value + deadpoints -- Add dead players points to killer's points end Power.Value = 0 --Set dead player's points to zero end) end)