Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Taking an IntValue's value and giving it to another IntValue??

local player = game.Players.LocalPlayer
local players = game.Players:GetChildren()

local points = Instance.new("IntValue", player)
points.Name = "Points"
points.Value = 0

local hv = Instance.new("IntValue", player)
hv.Name = "Extra"
hv.Value = 0

player.Chatted:connect(function(message)
if message == "points" then
for i, v in pairs(players) do
-- insert code here

How would I take the Value of Extra, and add it onto Points, and then remove Extra's value? I'm sorry if this is considered a request but I've been toying with this forever and I desperately need help.

Anything would be greatly appreciated!

1 answer

✓ Accepted answer

Alright, so how you would get that Value and then add it to one Value and then subtract that Value from another value is quiet simple. When doing arithmetic with values you have to address the Value property of them. So you would probably do something like this...

-- Adding
local player = game.Players.LocalPlayer
local players = game.Players:GetChildren()
local points = Instance.new("IntValue", player)

points.Name = "Points"
points.Value = 0
local hv = Instance.new("IntValue", player)
hv.Name = "Extra"
hv.Value = 0

player.Chatted:connect(function(message)
if message == "points" then
for i, v in pairs(players) do
local playerpoints = v:WaitForChild("Points")
playerpoints.Value = (playerpoints.Value) + hv.Value
end
end

--Subtracting
local player = game.Players.LocalPlayer
local players = game.Players:GetChildren()
local points = Instance.new("IntValue", player)

points.Name = "Points"
points.Value = 0
local hv = Instance.new("IntValue", player)
hv.Name = "Extra"
hv.Value = 0

player.Chatted:connect(function(message)
if message == "points" then
for i, v in pairs(players) do
local playerpoints = v:WaitForChild("Points")
playerpoints.Value = (playerpoints.Value) - (hv.Value)
end
end

Thank you for reading this question and I hope I helped! If you have any questions about this please don't be afraid to post them in the comments.

~~ KingLoneCat

This discussion is preserved as it was. New answers, comments, and votes are closed.