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

Can someone help me fix this code about cloning a handle for a GUI?

Asked by 4 years ago

Soooooooo Hi Yes it's me and I've followed another tutorial from AlvinBlox The script below is supposed to a script that adds an Image of a sword onto a GUI. For some reason, it doesn't work

-- Core UI localscript

local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local mainFrame = script.Parent:WaitForChild("MainFrame")
local safeArea = mainFrame:WaitForChild("SafeArea")
local itemInformation = safeArea:WaitForChild("ItemInformation")
local infoFrame = itemInformation.InfoFrame
local selectedItem = itemInformation.SelectedItem
local equippedItem = itemInformation.EquippedItem
local numberOfItems = #availableTools

local itemFrame = safeArea.ItemFrame
local shopButton = script.Parent:WaitForChild("ShopButton")
local buyButton = infoFrame.BuyButton
local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
local itemViewport = itemInformation.ItemViewport


shopButton.MouseButton1Click:Connect(function()
    mainFrame.Visible = not mainFrame.Visible
end)

local PADDING_X = 0.02
local DROPDOWN_Y = 0.2
local DROPDOWN_X = 0.25

local item1 = itemFrame:WaitForChild("Item1")

local box
local numRows = 1

for i = 1,numberOfItems,1 do

    if i == 1 then
        box = item1
    else

        box = item1:Clone()
        box.Name = "Item"..i
        box.Parent = itemFrame


        if (i-1) / (4*numRows) == 1 then
            numRows = numRows + 1
            box.Position = UDim2.new(PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_X*(numRows - 1))
        else
            box.Position = itemFrame["Item"..(i-1)].Position + UDim2.new(DROPDOWN_X,0,0,0)
        end

    end

    box.MouseButton1Click:Connect(function()
        for _, v in pairs(itemViewport:GetChildren()) do
            if not v: IsA("Frame")then
                v:Destroy()
            end
        end

        local itemViewportCam = Instance.new("Camera")
        print("Made camera")
        itemViewportCam.Parent = itemViewport

        local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
        handle.Parent = itemViewport
        print("Made Handle")

        itemViewport.CurrentCamera = itemViewportCam
        itemViewportCam.CFrame = handle.CameraCFrame.Value
        print("All of that stuff")

        local owned = game.ReplicatedStorage.ItemCheck:InvokeServer(availableTools[i][1])

        if equippedItem.Value == availableTools[i][1] then
            infoFrame.Cash.Text = "Owned"
            infoFrame.BuyButton.Text = "Unequip"
        elseif owned == true then
            infoFrame.Cash.Text = "Owned"
            infoFrame.BuyButton.Text = "Equip"
        else
            infoFrame.BuyButton.Text = "Buy"
            infoFrame.Cash.Text = "$"..availableTools[i][2]
        end

        infoFrame.ItemName.Text = availableTools[i][1]
        selectedItem.Value = availableTools[i][1]

        for _, v in pairs(itemFrame:GetChildren()) do
            if v:IsA("ImageButton") then
                v.BorderSizePixel = 0
            end

        end

        itemFrame["Item"..i].BorderSizePixel = 2

    end)

end

Thanks so much for helping me in advance.

1 answer

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

It is a really long script, and its hard to notice every single mistype or so, try pcalling it, pcalling tests the script if there is a error, and then it prints it to the output, as long as u do it like i did

local x, y = pcall(function()
local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local mainFrame = script.Parent:WaitForChild("MainFrame")
local safeArea = mainFrame:WaitForChild("SafeArea")
local itemInformation = safeArea:WaitForChild("ItemInformation")
local infoFrame = itemInformation.InfoFrame
local selectedItem = itemInformation.SelectedItem
local equippedItem = itemInformation.EquippedItem
local numberOfItems = #availableTools

local itemFrame = safeArea.ItemFrame
local shopButton = script.Parent:WaitForChild("ShopButton")
local buyButton = infoFrame.BuyButton
local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
local itemViewport = itemInformation.ItemViewport


shopButton.MouseButton1Click:Connect(function()
    mainFrame.Visible = not mainFrame.Visible
end)

local PADDING_X = 0.02
local DROPDOWN_Y = 0.2
local DROPDOWN_X = 0.25

local item1 = itemFrame:WaitForChild("Item1")

local box
local numRows = 1

for i = 1,numberOfItems,1 do

    if i == 1 then
        box = item1
    else

        box = item1:Clone()
        box.Name = "Item"..i
        box.Parent = itemFrame


        if (i-1) / (4*numRows) == 1 then
            numRows = numRows + 1
            box.Position = UDim2.new(PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_X*(numRows - 1))
        else
            box.Position = itemFrame["Item"..(i-1)].Position + UDim2.new(DROPDOWN_X,0,0,0)
        end

    end

    box.MouseButton1Click:Connect(function()
        for _, v in pairs(itemViewport:GetChildren()) do
            if not v: IsA("Frame")then
                v:Destroy()
            end
        end

        local itemViewportCam = Instance.new("Camera")
        print("Made camera")
        itemViewportCam.Parent = itemViewport

        local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
        handle.Parent = itemViewport
        print("Made Handle")

        itemViewport.CurrentCamera = itemViewportCam
        itemViewportCam.CFrame = handle.CameraCFrame.Value
        print("All of that stuff")

        local owned = game.ReplicatedStorage.ItemCheck:InvokeServer(availableTools[i][1])

        if equippedItem.Value == availableTools[i][1] then
            infoFrame.Cash.Text = "Owned"
            infoFrame.BuyButton.Text = "Unequip"
        elseif owned == true then
            infoFrame.Cash.Text = "Owned"
            infoFrame.BuyButton.Text = "Equip"
        else
            infoFrame.BuyButton.Text = "Buy"
            infoFrame.Cash.Text = "$"..availableTools[i][2]
        end

        infoFrame.ItemName.Text = availableTools[i][1]
        selectedItem.Value = availableTools[i][1]

        for _, v in pairs(itemFrame:GetChildren()) do
            if v:IsA("ImageButton") then
                v.BorderSizePixel = 0
            end

        end

        itemFrame["Item"..i].BorderSizePixel = 2

    end)

end end) if not x == true then warn(y) end 

I hope i was able to help! good day!

Ad

Answer this question