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

Why can't i use numbers greater than 10 in this script?

Asked by 7 years ago
Edited 7 years ago

This script basically checks to see if there are enough of a certain resource in a players pack and if there is it turns the text in a text-box green (so later another script knows there is enough). It works fine except I've noticed if I have more than 9 of an item in my player's pack, it doesn't recognize that i have enough. I'm wondering if It is because theres a problem with using double digits or something. Any ideas what it could be? (This is just the relevant part of the script so i don't show when i actually call the functions) Also I realize there's probably a better way to organize my variables but I'm relatively new to scripting so I do most things by "brute force" or any way I can get things done. So sorry about the mess :)

wait(3)

local player = game.Players.LocalPlayer

local BUTTON = script.Parent
local FRAME = BUTTON.Parent.Parent.Parent:WaitForChild("WoodenWallpiece")
local NBox1 = FRAME.ColumnFrame2.BoxFrame2
local NBox2 = FRAME.ColumnFrame2.BoxFrame3
local NBox3 = FRAME.ColumnFrame2.BoxFrame4
local NBox4 = FRAME.ColumnFrame2.BoxFrame5

local HBox1 = FRAME.ColumnFrame3.BoxFrame2
local HBox2 = FRAME.ColumnFrame3.BoxFrame3
local HBox3 = FRAME.ColumnFrame3.BoxFrame4
local HBox4 = FRAME.ColumnFrame3.BoxFrame5

local htext1 = HBox1.TextLabel
local ntext1 = NBox1.TextLabel
local htext2 = HBox2.TextLabel
local ntext2 = NBox2.TextLabel
local htext3 = HBox3.TextLabel
local ntext3 = NBox3.TextLabel
local htext4 = HBox4.TextLabel
local ntext4 = NBox4.TextLabel

FRAME.Visible = false

function check_Have()

    local PACK = player:FindFirstChild("Pack")
    local name = FRAME.RowFrame2.TextLabel.Text

local count = 0
for _, child in pairs(PACK:GetChildren()) do
    if child.Name == name then
        count = count + 1
else 
        count = count + 0
    end
htext1.Text = count

end
if PACK:FindFirstChild(name) == nil then 
    htext1.Text = "0" 
end

    print(count)
end

function check_enough()

    if htext1.Text >= ntext1.Text then 
        htext1.TextColor3 = Color3.new(0,85,0) print("enough")
    else
        htext1.TextColor3 = Color3.new(255,0,0) print("not enough")
    end

    end
1
Can you explain in plain English what exactly your script does, and what all of the variables mean? Monsieur_Robert 338 — 7y
0
Sure thing, so each of the boxes represent text boxes within a gui frame. the "N" boxes are how many of a resource is needed and the Gwolflover 80 — 7y
0
"H" boxes are how many of that resource the player has in his pack. So how it works is the Checkhave function checks how many resources with a specific name the player has in their pack, and then the checkenough function turns the text green if the amount the player has is >= what he needs and red if it's not enough. Gwolflover 80 — 7y
0
The script works unless the number of that specific resource that the player has is greater than 9. I'm thinking line 52 is where it is having the trouble because when it prints the count on line 47 that gives the right number, but if the number is greater than 9 the text turns red regardless of the fact that its greater than the number of resources needed. So pretty sure the problem is somewhere Gwolflover 80 — 7y

Answer this question