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

Players.coolmansunsh.PlayerGui.ShopGui.GuiHandler:34:index nil with 'CFrame?

Asked by 3 years ago

what did i do wrong and what does it mean?

local btn = script.Parent:WaitForChild("ShopBtn")
local shopFrame = script.Parent:WaitForChild("ShopBG")
local itemScroller = shopFrame.ItemScroller
local itemPreview = shopFrame.ItemPreview

shopFrame.Visible = false
itemPreview.Visible = false

btn.MouseButton1Click:Connect(function()


    shopFrame.Visible = not shopFrame.Visible
end)

local itemsFolder = game.ReplicatedStorage:WaitForChild("Items")

for i, item in pairs(itemsFolder:GetChildren()) do


    local name = item.Name
    local price = item.ShopGuiInfo.Price.Value
    local description = item.ShopGuiInfo.Description.Value

    local itemSelection = script.ItemSelection:Clone()

    local cam = Instance.new("Camera")
    cam.Parent = itemSelection.ItemView
    itemSelection.ItemView.CurrentCamera = cam


    local displayPart = item.Handle:Clone()
    displayPart.Anchored = true
    displayPart.CFrame = CFrame.new()
    displayPart.Parent = itemSelection.ItemView

    cam.CFrame = CFrame.new(displayPart.Position + displayPart.CFrame.LookVector * 4, displayPart.Position)

    itemSelection.Parent = itemScroller

    itemSelection.MouseButton1Click:Connect(function()

        itemPreview.ItemName.Text = name
        itemPreview.BuyButton.Text = "Buy for " .. price
        itemPreview.ItemDescription.Text = desc

        if itemPreview.ItemImage:FindFirstChild("Handle") then itemPreview.ItemImage.Handle:Destroy() end
        if itemPreview.ItemImage:FindFirstChild("Camera") then itemPreview.ItemImage.Camera:Destroy() end

        local cam = cam:Clone()
        cam.Parent = itemPreview.ItemImage
        itemPreview.ItemImage.CurrentCamera = cam2

        displayPart:Clone().Parent = itemPreview.ItemImage

        itemPreview.Visible = true
    end)
end


itemPreview.BuyButton.MouseButton1Click:Connect(function()

    game.ReplicatedStorage.OnItemBought:FireServer(itemsFolder[itemPreview.ItemName.Text])
end)

1 answer

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

you tried to access the CFrame of "displayPart" before giving it a parent, which is why it's returning nil. try this between lines 31 and 34

local displayPart = item.Handle:Clone()
displayPart.Parent = itemSelection.ItemView
displayPart.Anchored = true
displayPart.CFrame = CFrame.new()

hope this helps :D

Ad

Answer this question