pyxfluff
(Pyx)
January 7, 2022, 9:17pm
#1
Hi!
A quick issue with Viewport frames, is the subject is too small.
The code:
local function AddGUIs()
for i, v in pairs(Module) do
local SomeConstant = 5
Print("InPairs for AddGUI Started")
local NewVPF = Instance.new("ViewportFrame")
NewVPF.BackgroundColor3 = Color3.fromRGB(255,255,255)
NewVPF.BackgroundTransparency = 1
NewVPF.Name = i
NewVPF.Parent = loc
local Item = game.ReplicatedStorage.Assets.Data.Furniture[i]:Clone()
Item.Parent = NewVPF
local Cam = Instance.new("Camera")
Cam.Parent = NewVPF
Cam.CameraSubject = Item
NewVPF.CurrentCamera = Cam
--There's an error on this line Cam.CFrame = CFrame.new(v.PrimaryPart.CFrame.Position + (v.PrimaryPart.CFrame.LookVector * SomeConstant ), v.PrimaryPart.Position)
Cam.Focus = CFrame.new(0,0,Module[i].CameraPan)
local SelectButton = Instance.new("TextButton")
SelectButton.Text = ""
SelectButton.Font = Enum.Font.Gotham
SelectButton.TextColor3 = Color3.fromHSV(0, 0, 1)
SelectButton.BackgroundTransparency = 0.999
SelectButton.Size = UDim2.new(1,0,1,0)
SelectButton.Parent = NewVPF
SelectButton.Name = "Select"
local NewCorner = Instance.new("UICorner")
NewCorner.Parent = NewVPF
NewCorner.CornerRadius = UDim.new(0.15,0)
Print("Created ViewportFrame, SelectButton, and Corner, success, instance string instance, "..i.."/??"..ModuleAmount)
end
loaded = true
end
The sisue MIGHT be I need the CFrame, but I commented out the line, because it was causing issues.
Result:
Thanks for any help!
nicemike40
(nicemike40)
January 8, 2022, 4:06am
#2
You probably have to set the CFrame, yeah.
You don’t need to set the CameraSubject or the Focus.
Your CFrame line looks okay to me. What’s the error you get?
pyxfluff
(Pyx)
January 8, 2022, 4:07am
#3
CFrame is not a valid member of Camera, I think,. I’m readding it right now to get an accurate response.
Syntheix
(noah)
January 8, 2022, 4:12am
#5
Could you send the specific line of code? Along with any variable definitions that are being used at that time?
pyxfluff
(Pyx)
January 8, 2022, 4:13am
#6
Here’s the line. On line 440 I have
local SomeConstant = 5
Cam.CFrame = CFrame.new(v.PrimaryPart.CFrame.Position + (v.PrimaryPart.CFrame.LookVector * SomeConstant ), v.PrimaryPart.Position)
nicemike40
(nicemike40)
January 8, 2022, 4:27am
#7
Could be that v
doesn’t have a PrimaryPart, so when you do v.PrimaryPart.CFrame
it’s complaining
pyxfluff
(Pyx)
January 8, 2022, 4:28am
#8
If it’s a normal Mesh or part, doesn’t the script know that the PrimaryPart is the only part?
nicemike40
(nicemike40)
January 8, 2022, 4:31am
#9
Well, I don’t know what Module
is, but PrimaryPart
is something for Model
s.
It also doesn’t make much sense to me why you’re cloning game.ReplicatedStorage.Assets.Data.Furniture[i]
but then basing the Camera CFrame off of v
. Are these supposed to be the same thing?
pyxfluff
(Pyx)
January 8, 2022, 4:32am
#10
I dont really know why I did that looking back over it, and I will probably change it.
pyxfluff
(Pyx)
January 8, 2022, 4:33am
#11
Also, making a solution I got this.
nicemike40
(nicemike40)
January 8, 2022, 4:34am
#12
You probably meant v
.
i
is just a number that represents the index into the Module
table.
v
is the entry in that table itself.
1 Like
pyxfluff
(Pyx)
January 8, 2022, 4:34am
#13
yeah i did, sorry i’m an idiot and it’s 11:30
1 Like
pyxfluff
(Pyx)
January 8, 2022, 4:36am
#14
Still using v:IsA( I got a nil value.
This is an example entry for an item in my table.
Data.Template = {
DisplayName = "Template Item"
Model = ItemsFolder:WaitForChild("Item")
DisplayModel = Model
CameraRot = Vector3.new(0,0,0);
CameraPan = 4;
PlacementType = "ItemType";
Price = 10
SellPercent = 85; --85 = furniture, 80 = seasonal, 75 construction item
Description = "This is a template item, make sure to change most of it!";
Categories = {"All", "CHANGE_THIS", "CHANGE_THIS,", "etc"};
Item = true;
HasImage = false;
ImageNumber = 0;
}
nicemike40
(nicemike40)
January 8, 2022, 4:41am
#15
Well, yeah, there’s no IsA
in that table. There’s also no CFrame
in there.
I was operating under the assumption that Module
was full of actual Instance
s, not custom objects.
You’ll need to access the actual parts in that table like v.DisplayModel.CFrame
or v.DisplayModel:IsA
. I’m not sure exactly because I don’t know what all these things mean to you
pyxfluff
(Pyx)
January 8, 2022, 4:48am
#16
Now I have this, meaning it’s working, but I dont have CameraPan or CameraRotation implemented yet.
local function AddGUIs()
for i, v in pairs(Module) do
local SomeConstant = 5
Print("InPairs for AddGUI Started")
local NewVPF = Instance.new("ViewportFrame")
NewVPF.BackgroundColor3 = Color3.fromRGB(255,255,255)
NewVPF.BackgroundTransparency = 1
NewVPF.Name = i
NewVPF.Parent = loc
local Item = game.ReplicatedStorage.Assets.Data.Furniture[i]:Clone()
Item.Parent = NewVPF
local Cam = Instance.new("Camera")
Cam.Parent = NewVPF
Cam.CameraSubject = Item
NewVPF.CurrentCamera = Cam
if v.Model:IsA("Model") then
Cam.CFrame = CFrame.new(v.Model.PrimaryPart.CFrame.Position + (v.Model.PrimaryPart.CFrame.LookVector * SomeConstant ), v.Model.PrimaryPart.Position)
else
Cam.CFrame = CFrame.new(v.Model.CFrame.Position + (v.Model.CFrame.LookVector * SomeConstant ), v.Model.Position)
end
Cam.Focus = CFrame.new(0,0,Module[i].CameraPan)
local SelectButton = Instance.new("TextButton")
SelectButton.Text = ""
SelectButton.Font = Enum.Font.Gotham
SelectButton.TextColor3 = Color3.fromHSV(0, 0, 1)
SelectButton.BackgroundTransparency = 0.999
SelectButton.Size = UDim2.new(1,0,1,0)
SelectButton.Parent = NewVPF
SelectButton.Name = "Select"
local NewCorner = Instance.new("UICorner")
NewCorner.Parent = NewVPF
NewCorner.CornerRadius = UDim.new(0.15,0)
Print("Created ViewportFrame, SelectButton, and Corner, success, instance string instance, "..i.."/??"..ModuleAmount)
end
loaded = true
end
1 Like
nicemike40
(nicemike40)
January 8, 2022, 4:51am
#17
Nice! Sorry, were you asking a question or is this thread solved?
pyxfluff
(Pyx)
January 8, 2022, 4:53am
#18
It’s half working, look at the output, there’s an error on the model side. My guess is it tried to add a model, but I have an error with that.
nicemike40
(nicemike40)
January 8, 2022, 4:57am
#19
I don’t know what line that error is referring to, and I don’t know what your data looks like.
Try using the lua debugger to step through your code line-by-line and inspect what all the variables are at each line. That might help you to find your bug/find what is nil
when you expect it to be not-nil
.
pyxfluff
(Pyx)
January 8, 2022, 4:57am
#20
The error is on the line that’s dealing with the CFrame of Models.