Hello, I am trying to make a block grab system that stacks blocks.
I currently have the grabbing blocks ready, but not the stacking. My approach to stacking is to insert the parts in a table and get the offset from the size total size of Y.
The problem is that I can not get any parts in the table, I am trying to insert parts into the table, but when I print the stackTable its completely empty even if i just insert a part into the table, and print it in the next line. (The last 3 lines)
How could I fix this? I am really stuck.
This is a local script if that helps.
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local uis = game:GetService("UserInputService")
local hum = char:WaitForChild("Humanoid")
local CanGrabBlock = true
--The part where stacking blocks will be stored
local StackTable = {}
local function Block(plr, block)
print(StackTable)
if CanGrabBlock == true then
local offsetInformation = 0
--Find Offset if there is any
if #StackTable > 0 then
for i, blockIterate : BasePart in StackTable do
print(blockIterate)
local add = blockIterate.Size.Y
print(add)
offsetInformation += add
end
else
offsetInformation = 0
end
game.ReplicatedStorage.GrabEvents.GrabRequest:FireServer(plr, block, offsetInformation)
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.T then
game.ReplicatedStorage.GrabEvents.ReleaseRequest:FireServer(plr, block)
wait(1)
CanGrabBlock = true
end
end)
end
end
game.ReplicatedStorage.GrabEvents.SendClient.OnClientEvent:Connect(function(plr, block)
Block(plr, block)
table.insert(StackTable, block)
end)