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

Why wont my createlabel function work correctly?

Asked by 7 years ago

I am trying to make it easier by making a function that makes textlabels automatically

When I do this they are all together in one position.

local Plr = game.Players.LocalPlayer

local function Cc(Nme, Dsc, Prnt, Pos1)
    local t = Instance.new("TextLabel", Prnt)
    t.Name = Nme
    t.BackgroundTransparency = 0.35
    t.BackgroundColor3 = Color3.new(0,0,0)
    t.Size = UDim2.new(0,280,0,15)
    t.BorderSizePixel = 0
    t.TextColor3 = Color3.new(255,255,255)
    t.FontSize = Enum.FontSize.Size10
    t.TextWrapped = true
    t.Text = Dsc
    t.Position = UDim2.new(0,7.5,0,0+Pos1)
end

if Plr and Plr.PlayerGui then
    if Plr.PlayerGui:FindFirstChild("CommandsInterface") then
        game.Debris:AddItem(Plr.PlayerGui["CommandsInterface"],0)
    end
    local S = Instance.new("ScreenGui", Plr.PlayerGui)
    local F = Instance.new("Frame", S)
    local Sc = Instance.new("ScrollingFrame", F)
    local C = Instance.new("TextButton", F)
    S.Name = "CommandsInterface"
    F.Size = UDim2.new(0,300,0,300)
    F.Position = UDim2.new(0.5,-150,0.5,-150)
    F.Active = true
    F.Draggable = true
    F.BackgroundTransparency = 0.75
    F.BorderSizePixel = 3.5
    F.BorderColor3 = Color3.new(255,255,255)
    F.BackgroundColor3 = Color3.new(0,0,0)
    Sc.Size = F.Size
    Sc.BackgroundTransparency = 1
    Sc.Position = UDim2.new(0,0,0,0)
    C.TextColor3 = Color3.new(255,255,255)
    C.Font = Enum.Font.Arial
    C.FontSize = Enum.FontSize.Size14
    C.Position = UDim2.new(0,0,0,0)
    C.Text = "X"
    C.Size = UDim2.new(0,10,0,10)
    C.BackgroundTransparency = 1
    Cc("t1", "Shutdown  [Owners]",Sc,17)
    Cc("t2", "Clean  [All]",Sc,17)
    Cc("t3", "Fix  [All]",Sc,17)
    Cc("t4", "Disco  [All]",Sc,17)
    Cc("t5", "Music 'N'  [All]",Sc,17)
    C.MouseButton1Down:connect(function()
        game.Debris:AddItem(S,0)
    end)
end

Please help

0
not an answer, but those are some bad variable names Kampfkarren 215 — 7y
0
Variable names dont matter when they are just used in a script ;) BadLuke1 2 — 7y
0
To correct you, variable names do matter, you should never overwrite reserved commands with a variable name Sublimus 992 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

misiunicholas is right. The Pos1 argument is always set to 17 in the five calls in lines 44 to 48. Either change these, or do the following:

local Plr = game.Players.LocalPlayer
local lastTextLabelPosition = 0

local function Cc(Nme, Dsc, Prnt, Pos1)
    local t = Instance.new("TextLabel", Prnt)
    t.Name = Nme
    t.BackgroundTransparency = 0.35
    t.BackgroundColor3 = Color3.new(0,0,0)
    t.Size = UDim2.new(0,280,0,15)
    t.BorderSizePixel = 0
    t.TextColor3 = Color3.new(255,255,255)
    t.FontSize = Enum.FontSize.Size10
    t.TextWrapped = true
    t.Text = Dsc
    t.Position = UDim2.new(0,7.5,0,lastTextLabelPosition+Pos1)
    lastTextLabelPosition= lastTextLabelPosition+Pos1
end
Ad
Log in to vote
1
Answered by 7 years ago

Well when you execute the function from line 44 to 48 you set the argument Pos1 all to 17

Answer this question