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

How come this Creative Block Inventory Work? (solved)

Asked by 8 years ago
Edited 7 years ago

I was working on my script There was no errors but it does not create any of the Buttons! Why doesn't it work? (i have only included the part of the script that errors) EDIT: I included the full Script

--[[--[[--[[--[[
Setup Everything
--]]--]]--]]--]]
local mouse = game:GetService('Players').LocalPlayer:GetMouse()
local HotbarItems = {'Grass','Stone','Dirt','Sand','TorchWall','MoltenRock','Netherrack','Water','Lava'}
local ItemList = {'SpawnZombie','Fire','NetherPortal','Grass','Dirt','Stone','Bedrock','DiamondOre','CopperOre','IronOre','EmeraldOre','GoldOre','RedstoneOre','MoltenRock','Bricks','Leaves','WoolDarkGray','WoolOrange','WoolGray','WoolBrown','WoolDarkGreen','WoolLightGreen','WoolGreen','WoolBlue','WoolLightBlue','WoolLightYellow','SpruceWood','OakWood','DarkOakWood','AcaciaWood','AcaciaWoodPlanks','DarkOakWoodPlanks','OakWoodPlanks','SpruceWoodPlanks','Concrete','Cobblestone','Sand','Gravel','Netherrack','WoolRed','Water','Lava'}
local Selected = 1
local SpecialPlayers = {[148430515]='Co-Founder',[34929389]='Founder/Lead Developer'}
local PlayerColors = {[148430515]=Color3.new(255,170,0),[34929389]=Color3.new(255,0,0)}
game:GetService('Players').LocalPlayer.CharacterAdded:connect(function()
    game:GetService('Players').LocalPlayer.Character:WaitForChild('Humanoid')
    PunchAnim = game:GetService('Players').LocalPlayer.Character.Humanoid:LoadAnimation(script.Punch)
    PlaceAnim = game:GetService('Players').LocalPlayer.Character.Humanoid:LoadAnimation(script.Place)
end)
--[[--[[
Functions
--]]--]]
function CreativeItemClick(Button)
    Button.MouseButton1Click:connect(function()
        HotbarItems[Selected] = Button.ItemTag.Value
    end)
end
--[[
Chat
--]]

--[[--[[--[[--
Hotbar/Blocks
--]]--]]--]]--
mouse.Button1Down:connect(function()
    local target = mouse.Target
    PunchAnim:Play()
    if target.Parent:FindFirstChild('Humanoid') then
        target.Parent.Humanoid:TakeDamage(10)
        if target.Parent.Torso:FindFirstChild('Damaged') then
            target.Parent.Torso.Damaged:Play()
        else
            local Damaged = game:GetService('Lighting').Damaged:Clone()
            Damaged.Parent = target.Parent.Torso
            target.Parent.Torso.Damaged:Play()
        end
    end
    for index, value in ipairs(ItemList) do
        if target.Name == value then
            target:Destroy()
        end
    end
end)
mouse.Button2Down:connect(function()
    PlaceAnim:Play()
    local PlacedObjectIdentifier = HotbarItems[Selected]
    if HotbarItems[Selected] == 'SpawnZombie' then
        local Zombie = game:GetService('ReplicatedStorage').Mobs.Zombie:Clone()
        Zombie.Parent = game:GetService('Workspace')
        local p=mouse.Hit.p
        local x,y,z = p.x,p.y,p.z
        -- Added stuff
        local xdif = math.floor(x/4+.5)*4  -- Grids positions X value (0,4,8,12,16 etc)
        local ydif = math.floor(y/4+.5)*4  -- Grids positions Y value (0,4,8,12,16 etc)
        local zdif = math.floor(z/4+.5)*4  -- Grids positions Z value (0,4,8,12,16 etc)
        Zombie:MoveTo(Vector3.new(xdif,ydif,zdif))  
    else
        local ClonedBlock = game:GetService('Lighting'):FindFirstChild(PlacedObjectIdentifier):Clone()
        ClonedBlock.Parent = game:GetService('Workspace')
        local p=mouse.Hit.p
        local x,y,z = p.x,p.y,p.z
        -- Added stuff
        local xdif = math.floor(x/4+.5)*4  -- Grids positions X value (0,4,8,12,16 etc)
        local ydif = math.floor(y/4+.5)*4  -- Grids positions Y value (0,4,8,12,16 etc)
        local zdif = math.floor(z/4+.5)*4  -- Grids positions Z value (0,4,8,12,16 etc)
        ClonedBlock.CFrame = CFrame.new(xdif,ydif,zdif)
    end
end)
--[[--[[
Functions
--]]--]]
mouse.KeyDown:connect(function(key)
    local n=tonumber(key)
    if n then
        Selected = n
        script.Parent.Hotbar.Selecter:TweenPosition(UDim2.new((n-1)/10,0,0,0))
    end
end)
game:GetService('RunService').RenderStepped:connect(function()
    wait(.1)
    for i = 1, 9 do
        script.Parent.Hotbar["Slot"..i].Text = HotbarItems[i]:sub(1,2):upper()
    end
end)
--[[--[[--[
Inventories
--]]--]]--]
Row = 0
MaxSlotsPerRow = 9
Slot = 0
LastSlot = nil
script.Parent:WaitForChild('CreativeInventory')
for index, value in ipairs(ItemList) do
    Slot = Slot + 1
    local BlockName = string.sub(value,1,2)
    local BlockTag = string.upper(BlockName)
    BlockButton = game:GetService('Lighting').Item:Clone()
    BlockButton.Parent = script.Parent.CreativeInventory.Blocks
    if LastSlot == nil then
        BlockButton.Position = UDim2.new(0, BlockButton.Position.X.Offset + 25, 0, Row)
    else
        BlockButton.Position = UDim2.new(0, LastSlot.Position.X.Offset + 25, 0, Row)
    end
    BlockButton.Text = BlockTag
    BlockButton.ItemTag.Value = value
    CreativeItemClick(BlockButton)
    LastSlot = BlockButton
    if Slot >= MaxSlotsPerRow then
        Row = Row + 0.1
        Slot = 0
        BlockButton.Position = UDim2.new(0,0,Row,0)
    end
end
0
Could you narrow it dwn because this is too much to read through. Meltdown81 309 — 8y
0
We requested in the community chat for him to post the full script. TheeDeathCaster 2368 — 8y
0
Even though it may have said it wasn't correct, maybe studio misinterpreted your script for something else? brickzay 0 — 8y
0
i figured out the problem, the size of the button was using the Scale not the offset Thegrimdeathzombie 40 — 8y

Answer this question