Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script adding more than one to an IntValue?

Asked by 3 years ago
Edited 3 years ago

My script adds more than one value to an IntValue when cycling through the children of a folder. I made it so that if the child of the folder's BrickColor.Name is equal to a certain colour then it should add 1 to an IntValue of the corresponding name colour.

for i, v in pairs(game.Workspace.ColouredParts:GetChildren()) do

if v.BrickColor.Name == "Sea green"  then
game.Workspace.Counting.Green.Value = game.Workspace.Counting.Green.Value + 1

elseif v.BrickColor.Name == "Bright red" then 
    game.Workspace.Counting.Red.Value = game.Workspace.Counting.Red.Value + 1

elseif v.BrickColor.Name == "Electric blue" then
    game.Workspace.Counting.Blue.Value = game.Workspace.Counting.Blue.Value + 1

elseif v.BrickColor.Name == "Eggplant" then
    game.Workspace.Counting.Purple.Value = game.Workspace.Counting.Purple.Value + 1

elseif v.BrickColor.Name == "Burnt Sienna" then
    game.Workspace.Counting.Brown.Value = game.Workspace.Counting.Brown.Value + 1

elseif v.BrickColor.Name == "Bright yellow" then
    game.Workspace.Counting.Yellow.Value = game.Workspace.Counting.Yellow.Value + 1 

    end
end

the issue is when cycling through the script adds more than one to the values making it so IntValue's value is double the number of colours there actually is visible. eg if there are 2 yellows visible the IntValue displays "4".

Another way I can tell this is true is that the amount of all of the Intvalues add up to 50 when there are only 25 to add up... so,

Any help will be appreciated, thanks.

0
If there are mutliple parts with the same, brickcolor, it would add multiple times. JustinWe12 723 — 3y
0
Yeah there are but why is it adding more than once for each part with the same colour? iRedStoneCraftYT 0 — 3y
0
maybe u accidently duplicated the script TheUltimateTNTFriend 109 — 3y
0
I filtered the game and I only have one script with it's name iRedStoneCraftYT 0 — 3y
View all comments (4 more)
0
Can a game run two scripts at the same time because that might be the cause. iRedStoneCraftYT 0 — 3y
0
Games run all scripts that have been triggered to run. If there are multiple parts with the same brickcolor, the game would find all parts with that colour and increase the IntValue in all of them, causing this problem. Try to make each part a different color. AdSomnum 20 — 3y
0
the issue is i cant make the parts a different colour since they need to vary with some bieng the same colour its simon says sort of game iRedStoneCraftYT 0 — 3y
0
and second the issue isnt that the game is finding multiple with the same colour its that if theres for example 6 yellow parts on there, the scriptthat i made to add up the amount (6 yellows) adds 2 for each inside its correspondently named intvalue making 6 yellow parts but the value bieng 12 for some reason iRedStoneCraftYT 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I think i solved it by looking through a table instead of gettingchildren

Parts = {}
for I, v in pairs (game.Workspace.Folder:GetChildren())
table.insert(Parts, v)

for I, v in pairs(Parts)

forgot to post this a long while ago

Ad

Answer this question