if debounce == false then
if script.Parent.Frame.ScrollingFrame:FindFirstChild(material.Name) then
local mat = script.Parent.Frame.ScrollingFrame[material.Name]
mat.Count.Value = mat.Count.Value -1
mat.TextLabel.Text = material.Name.." x"..mat.Count.Value
material.Parent = game.Workspace
debounce = true
wait(1)
debounce = false
end
end
local xBlock = Block:Clone()
local owner = xBlock:WaitForChild("owner")
owner.Value = plr.name
xBlock.Position = target.Position + pos
game:GetService("ReplicatedStorage").PlaceShow:FireClient(plr,xBlock)
end)
Build tool
script.Parent.Activated:Connect(function()
local target = mouse.Target
if target then
local surface = mouse.TargetSurface
local pos = Surface(surface)
Event:FireServer(target,pos,Block_Choice)
end
end)
´´´
It basicaly look how to place the block and in which direction
local function Surface(surface)
if surface.Name == "Top" then
pos = Vector3.new(0,4,0)
elseif surface.Name == "Bottom" then
pos = Vector3.new(0,-4,0)
elseif surface.Name == "Front" then
pos = Vector3.new(0,0,-4)
elseif surface.Name == "Back" then
pos = Vector3.new(0,0,4)
elseif surface.Name == "Left" then
pos = Vector3.new(-4,0,0)
elseif surface.Name == "Right" then
pos = Vector3.new(4,0,0)
end
return pos
end
player.ChildAdded:connect(function()
while added ==0 do
for i, material in pairs(inv:GetChildren()) do
for e = 1, material.Value, 1 do
print("ADD Item to Inv")
if debounce == false then
if script.Parent.Frame.ScrollingFrame:FindFirstChild(material.Name) then
local mat = script.Parent.Frame.ScrollingFrame[material.Name]
mat.Count.Value = mat.Count.Value +1
mat.TextLabel.Text = material.Name.." x"..mat.Count.Value
else
local clone = script.ImageButton:Clone()
clone.Name = material.name
clone.TextLabel.Text = material.Name
clone.Count.Value = 1
clone.Parent = script.Parent.Frame.ScrollingFrame
end
debounce = true
wait(0.01)
debounce = false
end
end
end
added=added+1
end
end)
And there is always 1 material but the count change
Try to add an wait for child:
script.Parent.Frame.ScrollingFrame:WaitForChild(material.Name)
script.Parent.Frame.ScrollingFrame:FindFirstChild(material.Name)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local debounce = false
local open = false
local RemoveShow = ReplicatedStorage:WaitForChild('RemoveShow')
local PlaceShow = ReplicatedStorage:WaitForChild('PlaceShow')
local added = 0
local inv = player:WaitForChild("Inv")
script.Parent.Open.MouseButton1Click:Connect(function()
if open == false then
script.Parent.Frame.Visible = true
open = true
else
script.Parent.Frame.Visible = false
open = false
end
end)
This below Works why?
RemoveShow.OnClientEvent:Connect(function(material)
if debounce == false then
if script.Parent.Frame.ScrollingFrame:FindFirstChild(material.Name) then
local mat = script.Parent.Frame.ScrollingFrame[material.Name]
mat.Count.Value = mat.Count.Value +1
material:Destroy()
mat.TextLabel.Text = material.Name.." x"..mat.Count.Value
else
local clone = script.ImageButton:Clone()
clone.Name = material.name
clone.TextLabel.Text = material.Name
clone.Count.Value = 1
clone.Parent = script.Parent.Frame.ScrollingFrame
material:Destroy()
end
debounce = true
wait(1)
debounce = false
end
end)
This below dont Work
PlaceShow.OnClientEvent:Connect(function(material)
if debounce == false then
if script.Parent.Frame.ScrollingFrame:FindFirstChild(material.Name) then
local mat = script.Parent.Frame.ScrollingFrame[material.Name]
mat.Count.Value = mat.Count.Value -1
mat.TextLabel.Text = material.Name.." x"..mat.Count.Value
material.Parent = game.Workspace
else
local mat = script.Parent:WaitForChild("Frame").ScrollingFrame[material.Name]
mat.Count.Value = mat.Count.Value -1
mat.TextLabel.Text = material.Name.." x"..mat.Count.Value
material.Parent = game.Workspace
end
debounce = true
wait(1)
debounce = false
end
end)
Works below
player.ChildAdded:connect(function()
while added ==0 do
for i, material in pairs(inv:GetChildren()) do
for e = 1, material.Value, 1 do
print("ADD Item to Inv")
if debounce == false then
if script.Parent.Frame.ScrollingFrame:FindFirstChild(material.Name) then
local mat = script.Parent.Frame.ScrollingFrame[material.Name]
mat.Count.Value = mat.Count.Value +1
mat.TextLabel.Text = material.Name.." x"..mat.Count.Value
else
local clone = script.ImageButton:Clone()
clone.Name = material.name
clone.TextLabel.Text = material.Name
clone.Count.Value = 1
clone.Parent = script.Parent.Frame.ScrollingFrame
end
debounce = true
wait(0.01)
debounce = false
end
end
end
added=added+1
end
end)
i think i know what the problem is and it is in a tool i am propably not sending the block thats the code
-- Variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UIS = game:GetService('UserInputService')
local RS = game:GetService('ReplicatedStorage')
local tool = script.Parent
local Event = RS:WaitForChild('PlaceBlock')
local pos
local SBLOCK = player:WaitForChild('PlayerGui'):WaitForChild('Inventory').Frame.SBLOCK
-- Surface Detection
local function Surface(surface)
if surface.Name == "Top" then
pos = Vector3.new(0,4,0)
elseif surface.Name == "Bottom" then
pos = Vector3.new(0,-4,0)
elseif surface.Name == "Front" then
pos = Vector3.new(0,0,-4)
elseif surface.Name == "Back" then
pos = Vector3.new(0,0,4)
elseif surface.Name == "Left" then
pos = Vector3.new(-4,0,0)
elseif surface.Name == "Right" then
pos = Vector3.new(4,0,0)
end
return pos
end
-- Block Selection
local num = 1
local blocks = RS.Blocks:GetChildren()
local Block_Choice = blocks[1]
numberOfBlocks = #blocks
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
num += 1
Block_Choice = blocks[num]
if blocks[num] == nil then
num = 1
Block_Choice = blocks[1]
SBLOCK.Text ="Selected Block: "..Block_Choice.Name
end
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
num -= 1
Block_Choice = blocks[num]
if blocks[num] == nil then
num = numberOfBlocks
Block_Choice = blocks[numberOfBlocks]
SBLOCK.Text ="Selected Block: "..Block_Choice.Name
end
end
end)
-- Place Block
script.Parent.Activated:Connect(function()
local target = mouse.Target
if target then
local surface = mouse.TargetSurface
local pos = Surface(surface)
Event:FireServer(target,pos,Block_Choice)
end
end)