Problem showing how many studs of leght is for a part - lua

I got a problem while testing a billboard GUI that shows how many studs of length there are for the part but it doesn't show the studs it just stays zero I tried testing with a loop but didn't work then tried with RunService but still didn't work so I got really confused because it doesn't show any error in the output so please help
The code:
function setBill(text, parent)
local Loop = {}
local BillboardGui = Instance.new("BillboardGui")
local ScreenGui = Instance.new("ScreenGui")
local Frame = Instance.new("Frame")
local TextLabel = Instance.new("TextLabel")
BillboardGui.Parent = parent
BillboardGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
BillboardGui.Active = true
BillboardGui.AlwaysOnTop = true
BillboardGui.LightInfluence = 1.000
BillboardGui.Size = UDim2.new(0, 205, 0, 55)
BillboardGui.ResetOnSpawn = false
ScreenGui.Parent = BillboardGui
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
Frame.Parent = BillboardGui
Frame.BackgroundColor3 = Color3.fromRGB(71, 71, 71)
Frame.BackgroundTransparency = 1
Frame.BorderColor3 = Color3.fromRGB(255, 255, 255)
Frame.BorderSizePixel = 5
Frame.Size = UDim2.new(0, 150, 0, 50)
TextLabel.Parent = Frame
TextLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.BackgroundTransparency = 1.000
TextLabel.Size = UDim2.new(0, 150, 0, 50)
TextLabel.Font = Enum.Font.Gotham
TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.TextScaled = false
TextLabel.TextSize = 24.000
TextLabel.TextWrapped = true
local function BillLoop()
while wait() do
local pos = math.floor((BillboardGui.Parent.Position - BillboardGui.Parent.Position).magnitude)
TextLabel.Text = text.." Studs : "..tostring(pos)
end
end
Loop = game:GetService("RunService").RenderStepped:Connect(BillLoop)
end
setBill("Shop", game.Workspace["test part"])

local pos = math.floor((BillboardGui.Parent.Position
- BillboardGui.Parent.Position).magnitude)
TextLabel.Text = text.." Studs : "..tostring(pos)
This is where you calculate and set the text for your TextLabel.
BillboardGui.Parent.Position is a Vector3.
BillboardGui.Parent.Position - BillboardGui.Parent.Position is (0,0,0)
The magnitude aka length of a zero vector is 0.
This is probably not what you intended to calculate.

Related

Roblox GUI Kill Brick

I'm learning LUA and trying to make a GUI that spawns a brick above the players head which kills the player if touched. I'm not sure how to to connect the Touched event to a part that's spawned in with Instance.new? Here's what I got so far!
local button = script.Parent
local function kill()
button.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
button.parent.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
local player = game.Players.LocalPlayer.character
local killBrick = Instance.new("Part")
killBrick.Name = "Kill Brick"
killBrick.CFrame = player.Head.CFrame*CFrame.new(0,10,0)
killBrick.Parent = game.Workspace
killBrick.Color = Color3.fromRGB(255, 0, 0)
killBrick.Material = "Neon"
killBrick.BottomSurface = "Smooth"
killBrick.TopSurface = "Studs"
button.BackgroundColor3 = Color3.fromRGB(80, 80, 255)
button.parent.BackgroundColor3 = Color3.fromRGB(106, 146, 255)
end
button.MouseButton1Click:Connect(kill)
I fixed it by doing:
killBrick.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health=0
end
end)

How do i fix attemp to index nil with function in roblox?

I was making a module to make my in-game UI easier to build guis but I got this error when I was testing it: attempt to index nil with 'CreateWindow'
The code:
local FrameLib = {}
local TweenService = game:GetService("TweenService")
function FrameLib:CreateWindow(WindowName)
local UICornerMain = Instance.new("UICorner")
local UIListLayout = Instance.new("UIListLayout")
local cvb3 = Instance.new("ScreenGui")
local Main = Instance.new("Frame")
local Top = Instance.new("Frame")
local UICorner_2 = Instance.new("UICorner")
local Bottom = Instance.new("Frame")
local Close = Instance.new("TextButton")
local UICorner_3 = Instance.new("UICorner")
local Shadow = Instance.new("Folder")
local UmbraShadow = Instance.new("ImageLabel")
local PenumbraShadow = Instance.new("ImageLabel")
local AmbientShadow = Instance.new("ImageLabel")
local UICorner_4 = Instance.new("UICorner")
local Minimize = Instance.new("TextButton")
local UICorner_5 = Instance.new("UICorner")
local Shadow_2 = Instance.new("Folder")
local UmbraShadow_2 = Instance.new("ImageLabel")
local PenumbraShadow_2 = Instance.new("ImageLabel")
local AmbientShadow_2 = Instance.new("ImageLabel")
local TextLabel = Instance.new("TextLabel")
local Pattern = Instance.new("ImageLabel")
local AmbientShadow1 = Instance.new("ImageLabel")
local UIAspectRatioConstraint = Instance.new("UIAspectRatioConstraint")
local AmbientShadow2 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_2 = Instance.new("UIAspectRatioConstraint")
local PenumbraShadow1 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_3 = Instance.new("UIAspectRatioConstraint")
local PenumbraShadow2 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_4 = Instance.new("UIAspectRatioConstraint")
local UmbraShadow1 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_5 = Instance.new("UIAspectRatioConstraint")
local UmbraShadow2 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_6 = Instance.new("UIAspectRatioConstraint")
local Stroke = Instance.new("UIStroke")
local ButtonFrame = Instance.new("ScrollingFrame")
local Sections = Instance.new("Frame")
cvb3.Name = "Main"
cvb3.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
cvb3.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
Main.Name = "Main"
Main.Parent = cvb3
Main.AnchorPoint = Vector2.new(0, 0.5)
Main.BackgroundColor3 = Color3.fromRGB(63, 63, 63)
Main.BorderSizePixel = 0
Main.ClipsDescendants = true
Main.Position = UDim2.new(0.374725521, 0, 0.478996277, 0)
Main.Size = UDim2.new(0, 421, 0, 300)
UICornerMain.CornerRadius = UDim.new(0, 5)
UICornerMain.Parent = Main
Stroke.Name = "Stroke"
Stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Contextual
Stroke.Color = Color3.fromRGB(149,149,149)
Stroke.LineJoinMode = Enum.LineJoinMode.Round
Stroke.Thickness = 1
Stroke.Enabled = true
Stroke.Parent = Main
Top.Name = "Top"
Top.Parent = Main
Top.BackgroundColor3 = Color3.fromRGB(44, 44, 44)
Top.BorderSizePixel = 0
Top.Size = UDim2.new(0, 421, 0, 32)
UICorner_2.CornerRadius = UDim.new(0, 5)
UICorner_2.Parent = Top
Bottom.Name = "Bottom"
Bottom.Parent = Top
Bottom.BackgroundColor3 = Color3.fromRGB(44, 44, 44)
Bottom.BorderSizePixel = 0
Bottom.Position = UDim2.new(0, 0, 0.736249983, 0)
Bottom.Size = UDim2.new(0, 421, 0, 8)
Close.Name = "Close"
Close.Parent = Top
Close.BackgroundColor3 = Color3.fromRGB(38, 38, 38)
Close.BorderSizePixel = 0
Close.Position = UDim2.new(0.914489329, 0, 0.0625, 0)
Close.Selectable = false
Close.Size = UDim2.new(0, 28, 0, 29)
Close.ZIndex = 2
Close.Selected = true
Close.Font = Enum.Font.GothamSemibold
Close.Text = "X"
Close.TextColor3 = Color3.fromRGB(255, 255, 255)
Close.TextSize = 15.000
Close.TextWrapped = true
UICorner_3.CornerRadius = UDim.new(0, 5)
UICorner_3.Parent = Close
Shadow.Name = "Shadow"
Shadow.Parent = Close
UmbraShadow.Name = "UmbraShadow"
UmbraShadow.Parent = Shadow
UmbraShadow.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow.BackgroundTransparency = 1.000
UmbraShadow.BorderSizePixel = 0
UmbraShadow.Position = UDim2.new(0.5, 0, 0.5, 6)
UmbraShadow.Size = UDim2.new(1, 10, 1, 10)
UmbraShadow.Image = "rbxassetid://1316045217"
UmbraShadow.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow.ImageTransparency = 0.860
UmbraShadow.ScaleType = Enum.ScaleType.Slice
UmbraShadow.SliceCenter = Rect.new(10, 10, 118, 118)
PenumbraShadow.Name = "PenumbraShadow"
PenumbraShadow.Parent = Shadow
PenumbraShadow.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow.BackgroundTransparency = 1.000
PenumbraShadow.BorderSizePixel = 0
PenumbraShadow.Position = UDim2.new(0.5, 0, 0.5, 1)
PenumbraShadow.Size = UDim2.new(1, 18, 1, 18)
PenumbraShadow.Image = "rbxassetid://1316045217"
PenumbraShadow.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow.ImageTransparency = 0.880
PenumbraShadow.ScaleType = Enum.ScaleType.Slice
PenumbraShadow.SliceCenter = Rect.new(10, 10, 118, 118)
AmbientShadow.Name = "AmbientShadow"
AmbientShadow.Parent = Shadow
AmbientShadow.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow.BackgroundTransparency = 1.000
AmbientShadow.BorderSizePixel = 0
AmbientShadow.Position = UDim2.new(0.5, 0, 0.5, 3)
AmbientShadow.Size = UDim2.new(1, 5, 1, 5)
AmbientShadow.Image = "rbxassetid://1316045217"
AmbientShadow.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow.ImageTransparency = 0.800
AmbientShadow.ScaleType = Enum.ScaleType.Slice
AmbientShadow.SliceCenter = Rect.new(10, 10, 118, 118)
UICorner_4.CornerRadius = UDim.new(0, 5)
UICorner_4.Parent = Top
Minimize.Name = "Minimize"
Minimize.Parent = Top
Minimize.BackgroundColor3 = Color3.fromRGB(38, 38, 38)
Minimize.BorderSizePixel = 0
Minimize.Position = UDim2.new(0.831353962, 0, 0.0625, 0)
Minimize.Size = UDim2.new(0, 28, 0, 29)
Minimize.ZIndex = 2
Minimize.Font = Enum.Font.GothamSemibold
Minimize.Text = "-"
Minimize.TextColor3 = Color3.fromRGB(255, 255, 255)
Minimize.TextSize = 15.000
Minimize.TextWrapped = true
UICorner_5.CornerRadius = UDim.new(0, 5)
UICorner_5.Parent = Minimize
Shadow_2.Name = "Shadow"
Shadow_2.Parent = Minimize
UmbraShadow_2.Name = "UmbraShadow"
UmbraShadow_2.Parent = Shadow_2
UmbraShadow_2.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow_2.BackgroundTransparency = 1.000
UmbraShadow_2.BorderSizePixel = 0
UmbraShadow_2.Position = UDim2.new(0.5, 0, 0.5, 6)
UmbraShadow_2.Size = UDim2.new(1, 10, 1, 10)
UmbraShadow_2.Image = "rbxassetid://1316045217"
UmbraShadow_2.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow_2.ImageTransparency = 0.860
UmbraShadow_2.ScaleType = Enum.ScaleType.Slice
UmbraShadow_2.SliceCenter = Rect.new(10, 10, 118, 118)
PenumbraShadow_2.Name = "PenumbraShadow"
PenumbraShadow_2.Parent = Shadow_2
PenumbraShadow_2.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow_2.BackgroundTransparency = 1.000
PenumbraShadow_2.BorderSizePixel = 0
PenumbraShadow_2.Position = UDim2.new(0.5, 0, 0.5, 1)
PenumbraShadow_2.Size = UDim2.new(1, 18, 1, 18)
PenumbraShadow_2.Image = "rbxassetid://1316045217"
PenumbraShadow_2.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow_2.ImageTransparency = 0.880
PenumbraShadow_2.ScaleType = Enum.ScaleType.Slice
PenumbraShadow_2.SliceCenter = Rect.new(10, 10, 118, 118)
AmbientShadow_2.Name = "AmbientShadow"
AmbientShadow_2.Parent = Shadow_2
AmbientShadow_2.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow_2.BackgroundTransparency = 1.000
AmbientShadow_2.BorderSizePixel = 0
AmbientShadow_2.Position = UDim2.new(0.5, 0, 0.5, 3)
AmbientShadow_2.Size = UDim2.new(1, 5, 1, 5)
AmbientShadow_2.Image = "rbxassetid://1316045217"
AmbientShadow_2.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow_2.ImageTransparency = 0.800
AmbientShadow_2.ScaleType = Enum.ScaleType.Slice
AmbientShadow_2.SliceCenter = Rect.new(10, 10, 118, 118)
TextLabel.Parent = Top
TextLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.BackgroundTransparency = 1.000
TextLabel.Position = UDim2.new(0.0190023743, 0, 0.1875, 0)
TextLabel.Size = UDim2.new(0, 200, 0, 21)
TextLabel.Font = Enum.Font.GothamSemibold
TextLabel.Text = WindowName
TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.TextScaled = true
TextLabel.TextSize = 14.000
TextLabel.TextWrapped = true
TextLabel.TextXAlignment = Enum.TextXAlignment.Left
TextLabel.TextYAlignment = Enum.TextYAlignment.Top
Pattern.Name = "Pattern"
Pattern.Parent = Main
Pattern.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Pattern.BackgroundTransparency = 1.000
Pattern.Position = UDim2.new(-0.124703087, 0, -0.146666661, 0)
Pattern.Size = UDim2.new(0, 504, 0, 372)
Pattern.ZIndex = 0
Pattern.Image = "rbxassetid://2151741365"
Pattern.ImageTransparency = 0.400
Pattern.ScaleType = Enum.ScaleType.Tile
Pattern.SliceCenter = Rect.new(0, 256, 0, 256)
Pattern.TileSize = UDim2.new(0, 250, 0, 250)
AmbientShadow1.Name = "AmbientShadow1"
AmbientShadow1.Parent = cvb3
AmbientShadow1.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow1.BackgroundTransparency = 1.000
AmbientShadow1.BorderSizePixel = 0
AmbientShadow1.Position = UDim2.new(0.509783506, 0, 0.481963903, 3)
AmbientShadow1.Size = UDim2.new(0, 430, 0, 310)
AmbientShadow1.ZIndex = 0
AmbientShadow1.Image = "rbxassetid://1316045217"
AmbientShadow1.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow1.ImageTransparency = 0.800
AmbientShadow1.ScaleType = Enum.ScaleType.Slice
AmbientShadow1.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint.Parent = AmbientShadow1
UIAspectRatioConstraint.AspectRatio = 1.386
AmbientShadow2.Name = "AmbientShadow2"
AmbientShadow2.Parent = cvb3
AmbientShadow2.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow2.BackgroundTransparency = 1.000
AmbientShadow2.BorderSizePixel = 0
AmbientShadow2.Position = UDim2.new(0.509783506, 0, 0.481963903, 3)
AmbientShadow2.Size = UDim2.new(0, 430, 0, 310)
AmbientShadow2.ZIndex = 0
AmbientShadow2.Image = "rbxassetid://1316045217"
AmbientShadow2.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow2.ImageTransparency = 0.800
AmbientShadow2.ScaleType = Enum.ScaleType.Slice
AmbientShadow2.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_2.Parent = AmbientShadow2
UIAspectRatioConstraint_2.AspectRatio = 1.386
PenumbraShadow1.Name = "PenumbraShadow1"
PenumbraShadow1.Parent = cvb3
PenumbraShadow1.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow1.BackgroundTransparency = 1.000
PenumbraShadow1.BorderSizePixel = 0
PenumbraShadow1.Position = UDim2.new(0.509274423, 0, 0.48696661, 1)
PenumbraShadow1.Size = UDim2.new(0, 431, 0, 309)
PenumbraShadow1.ZIndex = 0
PenumbraShadow1.Image = "rbxassetid://1316045217"
PenumbraShadow1.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow1.ImageTransparency = 0.880
PenumbraShadow1.ScaleType = Enum.ScaleType.Slice
PenumbraShadow1.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_3.Parent = PenumbraShadow1
UIAspectRatioConstraint_3.AspectRatio = 1.398
PenumbraShadow2.Name = "PenumbraShadow2"
PenumbraShadow2.Parent = cvb3
PenumbraShadow2.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow2.BackgroundTransparency = 1.000
PenumbraShadow2.BorderSizePixel = 0
PenumbraShadow2.Position = UDim2.new(0.509274423, 0, 0.48696661, 1)
PenumbraShadow2.Size = UDim2.new(0, 431, 0, 309)
PenumbraShadow2.ZIndex = 0
PenumbraShadow2.Image = "rbxassetid://1316045217"
PenumbraShadow2.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow2.ImageTransparency = 0.880
PenumbraShadow2.ScaleType = Enum.ScaleType.Slice
PenumbraShadow2.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_4.Parent = PenumbraShadow2
UIAspectRatioConstraint_4.AspectRatio = 1.398
UmbraShadow1.Name = "UmbraShadow1"
UmbraShadow1.Parent = cvb3
UmbraShadow1.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow1.BackgroundTransparency = 1.000
UmbraShadow1.BorderSizePixel = 0
UmbraShadow1.Position = UDim2.new(0.509783506, 0, 0.478506416, 6)
UmbraShadow1.Size = UDim2.new(0, 430, 0, 308)
UmbraShadow1.ZIndex = 0
UmbraShadow1.Image = "rbxassetid://1316045217"
UmbraShadow1.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow1.ImageTransparency = 0.860
UmbraShadow1.ScaleType = Enum.ScaleType.Slice
UmbraShadow1.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_5.Parent = UmbraShadow1
UIAspectRatioConstraint_5.AspectRatio = 1.395
UmbraShadow2.Name = "UmbraShadow2"
UmbraShadow2.Parent = cvb3
UmbraShadow2.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow2.BackgroundTransparency = 1.000
UmbraShadow2.BorderSizePixel = 0
UmbraShadow2.Position = UDim2.new(0.509783506, 0, 0.478506416, 6)
UmbraShadow2.Size = UDim2.new(0, 430, 0, 308)
UmbraShadow2.ZIndex = 0
UmbraShadow2.Image = "rbxassetid://1316045217"
UmbraShadow2.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow2.ImageTransparency = 0.860
UmbraShadow2.ScaleType = Enum.ScaleType.Slice
UmbraShadow2.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_6.Parent = UmbraShadow2
UIAspectRatioConstraint_6.AspectRatio = 1.395
ButtonFrame.Name = "ButtonFrame"
ButtonFrame.Parent = Main
ButtonFrame.Active = true
ButtonFrame.BackgroundColor3 = Color3.fromRGB(44, 44, 44)
ButtonFrame.BorderSizePixel = 0
ButtonFrame.Position = UDim2.new(0, 0, 0.106666669, 0)
ButtonFrame.Size = UDim2.new(0, 88, 0, 268)
ButtonFrame.ScrollBarThickness = 0
UIListLayout.HorizontalAlignment = Enum.HorizontalAlignment.Left
UIListLayout.Parent = ButtonFrame
AmbientShadow.Parent = Main
AmbientShadow1.Parent = Main
AmbientShadow2.Parent = Main
PenumbraShadow.Parent = Main
PenumbraShadow1.Parent = Main
PenumbraShadow2.Parent = Main
UmbraShadow.Parent = Main
UmbraShadow1.Parent = Main
UmbraShadow2.Parent = Main
AmbientShadow.Position = UDim2.new(0.498, 0,0.506, 3)
AmbientShadow1.Position = UDim2.new(0.498, 0,0.506, 3)
AmbientShadow2.Position = UDim2.new(0.498, 0,0.506, 3)
PenumbraShadow.Position = UDim2.new(0.498, 0,0.506, 3)
PenumbraShadow1.Position = UDim2.new(0.498, 0,0.506, 3)
PenumbraShadow2.Position = UDim2.new(0.498, 0,0.506, 3)
UmbraShadow.Position = UDim2.new(0.498, 0,0.506, 3)
UmbraShadow1.Position = UDim2.new(0.498, 0,0.506, 3)
UmbraShadow2.Position = UDim2.new(0.498, 0,0.506, 3)
AmbientShadow.ZIndex = -1
AmbientShadow1.ZIndex = -1
AmbientShadow2.ZIndex = -1
PenumbraShadow.ZIndex = -1
PenumbraShadow1.ZIndex = -1
PenumbraShadow2.ZIndex = -1
UmbraShadow.ZIndex = -1
UmbraShadow1.ZIndex = -1
UmbraShadow2.ZIndex = -1
Sections.Name = "Sections"
Sections.Parent = Main
Sections.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Sections.BackgroundTransparency = 1.000
Sections.Position = UDim2.new(0.211401418, 0, 0.109999999, 0)
Sections.Size = UDim2.new(0, 332, 0, 267)
local PatStroke = Instance.new("UIStroke")
local PatCorner = Instance.new("UICorner")
PatCorner.Parent = Pattern
PatCorner.CornerRadius = UDim.new(0,5)
PatStroke.Parent = Pattern
PatStroke.Color = Color3.fromRGB(149, 149, 149)
PatStroke.LineJoinMode = Enum.LineJoinMode.Round
Pattern.ZIndex = 0
Pattern.BackgroundColor3 = Color3.fromRGB(63, 63, 63)
Pattern.BackgroundTransparency = 0
end
I was searching about this error with a function but I couldn't find any so I'm trying if here I can get any help about this error because I have been working very hard on this to make my GUI easier to build but well it's now struggling me to find any solutions.
The error is not in the provided code.
It must be something where you do.
someVariable["CreateWindow"], someVariable.CreateWindow or someVariable:CreateWindow() where someVariable is a nil value. Indexing nil values is not allowed.
You failed to refer that variable to your FrameLib table. Maybe just a typo? Lua errors typically come with a stack trace that provides you with information about which line of which file cause the error together with the sequence of function calls that lead to that error.
If you don't know the three possible indexing operations in Lua and hence what to look for in this case you probably should revisit the basics of Lua befor doing any further Roblox development.

how do I fix my script made in Roblox Lua?

I'm making my script and the Script Analysis tool says
Error: (54,2) Expected , got 'end'
I thought maybe you guys might help.
Here is the code
-- to be placed in StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- wait for local player PlayerGui
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- create a ScreenGui
local screenGui = Instance.new("ScreenGui", playerGui)
-- create a holder for our bar
local frame = Instance.new("Frame", screenGui)
frame.AnchorPoint = Vector2.new(0.0, 0.0)
frame.Position = UDim2.new(0.0, 0, 0.0, 0)
frame.Size = UDim2.new(0.0, 0, 0.0, 0)
-- create a bar
local bar = Instance.new("Frame", frame)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.Size = UDim2.new(1, 0, 1, 0)
bar.BackgroundColor3 = Color3.new(0, 1, 0)
-- create a sound
local sound = Instance.new("Sound", screenGui)
local lastLoudness = 0
sound.SoundId = "rbxassetid://697821987"
sound.Looped = true
sound:Play()
-- define a max loudness
local maxLoudness = 30
-- animate the amplitude bar
while true do
local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
print(80-(game.Workspace.CurrentCamera.FieldOfView))
bar.Size = UDim2.new(sound.PlaybackLoudness / maxLoudness, 0, 0, 0)
wait(0.00001)
local lastLoudness = 0
local PBS = ((sound.PlaybackLoudness/50)^(sound.PlaybackLoudness/50))
if lastLoudness~=0 then
local formula = math.abs((lastLoudness*15)) + ((lastLoudness+PBS)/1.9)
if (math.abs(PBS) > formula) == true then
game.Workspace.CurrentCamera.FieldOfView = (lastLoudness)
if game.Workspace.CurrentCamera.FieldOfView <= 10 then
print(formula, PBS)
else
game.Workspace.CurrentCamera.FieldOfView = 0
print(formula, PBS)
end
end
end
end
end
end
I genuinely Don't know how to fix the code, So...
Could you guys Help me?
I spent a long time (a couple of hours) on this and I'm legitimately stuck in the deepest pits of coding hell. And I want this fixed SO BADLY.
Also, Just To Clarify, The script is supposed to change FOV when sound.PlaybackLoudness ÷ 50 × sound.PlaybackLoudness ÷ 50 is over 0.
Egor Skriptunoff is right. Let me reformat your while-loop to show you why.
-- animate the amplitude bar
while true do
local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
print(80-(game.Workspace.CurrentCamera.FieldOfView))
bar.Size = UDim2.new(sound.PlaybackLoudness / maxLoudness, 0, 0, 0)
wait(0.00001)
local lastLoudness = 0
local PBS = ((sound.PlaybackLoudness/50)^(sound.PlaybackLoudness/50))
if lastLoudness~=0 then
local formula = math.abs((lastLoudness*15)) + ((lastLoudness+PBS)/1.9)
if (math.abs(PBS) > formula) == true then
game.Workspace.CurrentCamera.FieldOfView = (lastLoudness)
if game.Workspace.CurrentCamera.FieldOfView <= 10 then
print(formula, PBS)
else
game.Workspace.CurrentCamera.FieldOfView = 0
print(formula, PBS)
end
end
end
end
end -- <-- these bad boys don't go with anything
end -- <-- just remove them to get rid of the error
EDIT : Here's a more complete answer to help with your other script issues. You were resizing your animation stuff to 0 pixels tall, so you couldn't see anything.
-- to be placed in StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- wait for local player PlayerGui
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- create a ScreenGui
local screenGui = Instance.new("ScreenGui", playerGui)
-- create a holder for our bar
local frame = Instance.new("Frame", screenGui)
frame.AnchorPoint = Vector2.new(0.0, 0.0)
frame.Position = UDim2.new(0.0, 0, 0.0, 0)
frame.Size = UDim2.new(1.0, 0, 0.0, 50) -- <-- this is no longer invisible
-- create a bar
local bar = Instance.new("Frame", frame)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.Size = UDim2.new(1, 0, 1, 0)
bar.BackgroundColor3 = Color3.new(0, 1, 0)
-- create a sound
local sound = Instance.new("Sound", screenGui)
local lastLoudness = 0
sound.SoundId = "rbxassetid://697821987"
sound.Looped = true
sound:Play()
-- define a max loudness
local maxLoudness = 30.0 -- <-- this needed to be a decimal value
local lastLoudness = 0
-- animate the amplitude bar
while true do
-- PlaybackLoudness values range from 0 to 500, so downscale it
local sampledLoundness = (sound.PlaybackLoudness / 50)
local amplitude = math.clamp(sampledLoundness / maxLoudness, 0, 1)
print("sound values : ", sound.PlaybackLoudness, maxLoudness, amplitude)
-- animate the bar
bar.Size = UDim2.new(amplitude, 0, 1, 0) -- <-- this was squashed to 0 pixels
wait(0.00001)
-- create a camera shake effect
-- NOTE - not sure what the expected behavior is here, it just zooms in
local PBS = sampledLoundness ^ sampledLoundness
if lastLoudness ~=0 then
local formula = math.abs(lastLoudness * 15) + ((lastLoudness + PBS) / 1.9)
if (math.abs(PBS) > formula) == true then
game.Workspace.CurrentCamera.FieldOfView = lastLoudness
if game.Workspace.CurrentCamera.FieldOfView <= 10 then
print("FOV is less than 10 : ", formula, PBS)
else
game.Workspace.CurrentCamera.FieldOfView = 0
print("FOV forced to 0 : ", formula, PBS)
end
end
end
-- update lastLoudness and loop
lastLoudness = sampledLoundness
end

Corona app's purple background in xCodeSimulator

I have a corona app, with two storyboard scenes (scene1.lua, addDesire.lua).
I show addDesire.lua as an overlay:
function onAddPurchase( event )
if event.phase == "ended" then
local options = {
effect = "fromBottom",
time = 500,
isModal = true,
}
storyboard.showOverlay( "addDesire", options )
end
end
In Corona Simulator everything works, but in xCode simulator a pink background appears in several cases.
1) When addDesire.lua appears after onAddPurchase it looks like:
When it should look like:
2) When I close addDesire.lua (tapping on Cancel button) this appears:
There is something even stranger going on under the hood:
addDesire.lua has 2 textFields and 1 textBox which is created in function scene:createScene( event ). If I comment out the code that creates these objects everything works perfectly.
function scene:createScene( event )
local group = self.view
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local _W = display.contentWidth
local _H = display.contentHeight
local bg = display.newImageRect( "assets/dollar.png", 360, 570 )
bg:toBack()
bg.x, bg.y = _W/2, _H/2
bg:addEventListener( "tap", function() native.setKeyboardFocus(nil); end)
group:insert(bg)
-- Rounded Rect Alpha
roundedRect = display.newRoundedRect( 5, 5, _W*0.9, _H*0.8, 10 )
roundedRect.x, roundedRect.y = centerX, centerY
roundedRect:setFillColor( 0/255, 0/255, 0/255, 170/255 )
group:insert(roundedRect)
-- Label Title
titleLabel = display.newText( "Purchase", 0, 0, "AmericanTypewriter-Bold", 20 )
titleLabel.x, titleLabel.y = centerX, _H*0.15
group:insert(titleLabel)
-- Label Fam
nameLabel = display.newText( "Name", 0, 0, "AmericanTypewriter", 18 )
nameLabel.x, nameLabel.y = centerX, _H*0.20
group:insert(nameLabel)
-- Edit Fam
nameText = native.newTextField(_W/2, _H*0.26, 240, 30)
nameText.font = native.newFont(native.systemFont, 18)
nameText:addEventListener( "userInput", inputListener )
group:insert(nameText)
-- Label Name
descriptionLabel = display.newText( "Description", 0, 0, "AmericanTypewriter", 16 )
descriptionLabel.x, descriptionLabel.y = centerX, _H*0.31
group:insert(descriptionLabel)
-- Edit Name
descriptionText = native.newTextBox(_W/2, _H*0.44, 240, 100)
descriptionText.font = native.newFont(native.systemFont, 14)
descriptionText.isEditable = true
descriptionText:addEventListener( "userInput", inputListener )
group:insert(descriptionText)
-- Label Deposit
costLabel = display.newText( "Cost", 0, 0, "AmericanTypewriter", 16 )
costLabel.x, costLabel.y = centerX, _H*0.57
group:insert(costLabel)
-- Edit Deposit
costText = native.newTextField(_W/2, _H*0.64, 240, 30)
costText.font = native.newFont(native.systemFont, 18)
costText.inputType = "number"
costText.align = "center"
costText:addEventListener( "userInput", inputListener )
group:insert(costText)
-- Button Save & Start game
btnSave = widget.newButton {
width = _W*0.4,
height = 50,
--defaultFile = "buttonDefault.png",
--overFile = "buttonOver.png",
label = "Buy",
onEvent = onSaveData
}
btnSave.x, btnSave.y = _W/2, costLabel.y+150
group:insert(btnSave)
-- Button Cancel
btnCancel = widget.newButton {
width = _W*0.8,
height = 50,
--defaultFile = "buttonDefault.png",
--overFile = "buttonOver.png",
label = "Cancel",
onEvent = onExit,
}
btnCancel.x, btnCancel.y = _W/2, btnSave.y+50
group:insert(btnCancel)
end
What is going on?
The answer is here guys: native.textField

how to go back in lua file from another lua file?

I have a menu lua and when i choose 1 of the category (the "songselect" lua) and go back to the menu lua i got this error:
Runtime error
...ocuments\corona projects\singingbeemenu\director.lua:151: attempt to
call field 'unloadMe' (a nil value)
stack traceback:
[C]: in function 'unloadMe'
...ocuments\corona projects\singingbeemenu\director.lua:151: in function
'_listener
'
this is 1 of my category the songselect.lua
module(..., package.seeall)
display.setStatusBar( display.HiddenStatusBar )
function new()
local localGroup = display.newGroup()
local tableView = require("tableView")
local ui = require("ui")
--------------------------------------------------------------------------
local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight
local songList
local backBtn
local detailScreenText
local background = display.newRect(0, 0, display.contentWidth, display.contentHeight)
background:setFillColor(0, 0, 0)
local data = {}
--iPad: setup a color fill for selected items
local selected = display.newRect(0, 0, 50, 50) --add acolor fill to show the selected item
selected:setFillColor(67,141,241,180) --set the color fill to light blue
selected.isVisible = false --hide color fill until neede
-----------------------------------------------
data[1] = {}
data[1].title = "Crazy Song"
data[1].subtitle = "by Bruno Earth"
data[1].image = "note.png"
data[2] = {}
data[2].title = "Enter Sunman"
data[2].subtitle = "by Mentalica"
data[2].image = "note.png"
local topBoundary = display.screenOriginY + 40
local bottomBoundary = display.screenOriginY + 0
songList = tableView.newList{
data=data,
default="listItemBg.png",
over="listItemBg_over.png",
top=topBoundary,
bottom=bottomBoundary,
callback = function( row )
local g = display.newGroup()
local img = display.newImage(row.image)
g:insert(img)
img.x = math.floor(img.width*0.5 + 6)
img.y = math.floor(img.height*0.5)
local title = display.newText( row.title, 0, 0, native.systemFontBold, 16 )
title:setTextColor(0,0,0)
g:insert(title)
title.x = title.width*0.5 + img.width + 6
title.y = 30
local subtitle = display.newText( row.subtitle, 0, 0, native.systemFont, 14 )
subtitle:setTextColor(80,80,90)
g:insert(subtitle)
subtitle.x = subtitle.width*0.5 + img.width + 6
subtitle.y = title.y + title.height + 6
return g
end
}
local function scrollToTop()
songList:scrollTo(topBoundary-1)
end
local navBar = display.newImage("navBar.png")
navBar.x = display.contentWidth*.5
navBar.y = math.floor(display.screenOriginY + navBar.height*0.5)
local navHeader = display.newText("Song Lists", 0, 0, native.systemFontBold, 16)
navHeader:setTextColor(255, 255, 255)
navHeader.x = display.contentWidth*.5
navHeader.y = navBar.y
--Setup the back button
local backToMenu = function(event)
print (event.phase)
if event.phase == 'ended' then
print ("ok")
director:changeScene(event.target.scene, "fade")
print ("back!")
end
end
backBtn = display.newImage("backButton.png")
backBtn.x = math.floor(backBtn.width/2) + backBtn.width + screenOffsetW
backBtn.y = navBar.y
backBtn.scene = "menu"
backBtn:addEventListener("touch", backToMenu)
--backBtn.alpha = 0
local listBackground = display.newRect( 0, 0, songList.width, songList.height )
listBackground:setFillColor(255,255,255)
songList:insert(1,listBackground)
return localGroup
end
is it impossible the go back method in lua?
can anyone can help me and give an idea why i got the error?
thanks in advance...
I got this, i change my director.lua to the latest version...
Try this Lua file to solve your problem.

Resources