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

Why Are The Buttons Cluttering Up In Certain Area?

Asked by 7 years ago
Edited 7 years ago

I have been trying to get this working for a couple hours now but it is just not working, i will show the script now, and there were no errors, if you want to see what i mean Play this place and Press E: https://web.roblox.com/games/588166455/Universal-Worlds-Map-Template

--[[--[[--[[--[[
Setup Everything
--]]--]]--]]--]]
local mouse = game:GetService('Players').LocalPlayer:GetMouse()
local HotbarItems = {'Grass','Stone','Dirt','Sand','TorchWall','MoltenRock','Netherrack','Water','Lava'}
local ItemList = {'Glowstone','CorrodedMetal','DiamondPlate','Ice','Metal','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','EGreenCorrodedMetal','EDiamondPlate','ETimeFracture','ERedNeon'}
local Selected = 1
local SpecialPlayers = {148430515,34929389}
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
        if n >= 1 then
            if n <= 9 then
                Selected = n
                script.Parent.Hotbar.Selecter:TweenPosition(UDim2.new((n-1)/10,0,0,0))
            end
        end
    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
ExperimentalPlayer = false
script.Parent:WaitForChild('CreativeInventory') -- this is where it creates the buttons
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 + 100, 0, Row + 100)
    else
        BlockButton.Position = UDim2.new(0, LastSlot.Position.X.Offset + 100, 0, Row + 100)
    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

Answer this question