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

I want to make a lag testing game so to say but my script is not working ????

Asked by 4 years ago

the problem is at line 13 (the one with a comment) I don't know how to make it say "parts = number(the number of parts I spawned)"

local g = "Times"
local number = 1
local text = game.StarterGui.ScreenGui.TextLabel

while number < 50 do
    Instance.new("Part",workspace)
    print(g,number)
    wait(0.2)
    number = number+1   
end

while 3 ==3 do
    text.Text = "parts =",number --here
end

3 answers

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

The reason you got an error is because the value is a number value and not a string value. Use tostring(value here) to convert it.

New Code:

local g = "Times"
local number = 1
local text = game.StarterGui.ScreenGui.TextLabel

while number < 50 do
    Instance.new("Part",workspace)
    print(g,number)
    wait(0.2)
    number = number+1   
end

while 3 ==3 do
    text.Text = "parts =",tostring(number) --use tostring
end

Good luck on that lag test!

0
thanks HeroFigo 81 — 4y
0
HeroFig, please consider accepting the answer. rayhansatria 142 — 4y
Ad
Log in to vote
0
Answered by
OhManXDXD 445 Moderation Voter
4 years ago
Edited 4 years ago

Add a .. to any string to add a part of the code to it.


local g = "Times" local number = 1 local text = game.StarterGui.ScreenGui.TextLabel while number < 50 do Instance.new("Part",workspace) print(g,number) wait(0.2) number = number+1 end while wait() do -- use this instead because while 3 == 3 is pretty much while true do and you need a wait to stop your game from crashing. text.Text = "parts = " .. number end
Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

Not sure if this is still needed but i've re-wrote your script to include a percent bar on your text button. The code is as follows:

local STGui = game:GetService("StarterGui")
local Screen = STGui.ScreenGui

local PerBar_Props = {
    ClassName = "Frame",
    Parent = Screen,
    Name = "Bar",
    BackgroundColor3 = Color3.fromRGB(81, 38, 255),
    BackgroundTransparency = 0.3,
    Position = UDim2.new(0,0,0,0),
    Size = UDim2.new(0,0,1,0),
    ZIndex = 1,
    Visible = false,
}  


function createElement(Props)
    local ClassName = Props.ClassName
    --print(Props.Name,ClassName)
    local Obj = Instance.new(ClassName) 
    for k,v in pairs(Props) do
        if(k ~= "ClassName") then
            Obj[k] = v
        end
    end
    return Obj
end
local text = game.StarterGui.ScreenGui.TextLabel
text.TextStrokeColor3 = text.BackgroundColor3
text.TextStrokeTransparency = 0

PerBar_Props.Parent = text
local PBar = createElement(PerBar_Props)

--// change this value to change how many parts you want to load!
local howmany = 500

local Part_Props = {
    ClassName = "Part",
    Parent = workspace,
    Position = Vector3.new(0,0.5,0),
    Name = "Part"
}

for i=1,howmany do
    local P = createElement(Part_Props)
    wait(0.2)
    text.Text = "parts ="..tostring(i)
    local Percent = (i/howmany)
    --print(Percent)
    PBar.Visible = true
    PBar.Size = UDim2.new(Percent,0,1,0)
end

The createElement() function is just a function that would create an object int this instance i create a frame that matches your textLabel Size and position then i also use it to create the parts. To target a property of your part just include the value inside the table Part_Props

Something like:

local Part_Props = {
    ClassName = "Part",
    --// new entries!
    Anchored = true,
    Color = Color3.fromRGB(0,255,255),
    --//
    Parent = workspace,
    Position = Vector3.new(0,0.5,0),
    Name = "Part"
}

Then re-run the script to see the changes. Though make sure you match the propety exactly otherwise the script will throw an error

Example:

local Part_Props = {
    ClassName = "Part",
    Parent = workspace,
    color = Color3.fromRGB(0,255,255), -- this wont work the letter c MUST be a Capital!
    somethingelse = "blah",             -- this will not work either as somethingelse isnt a property of a Part!
    Position = Vector3.new(0,0.5,0),
    Name = "Part"
}

Hope this helps! :)

0
thank you for scripting a game in one comment but i just need someone to test the script for me and thell me why it doesn't work.  HeroFigo 81 — 4y
0
ok the problem was that i left the script in the server gui folder HeroFigo 81 — 4y

Answer this question