When I click the button to the item it doesn't place the item.

LocalScript:

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local Items = game:GetService("ReplicatedStorage").Items
local PBase = Player:WaitForChild("Base")
local PlaceMentModule = require(script.PlacementModule)
local GridSize = 3
local RBase = PBase.Value
local Plane = PlaceMentModule.new(RBase,RBase.ItemHolder,GridSize)
local ItemObject
local ItemName
local Signal
local PrevItem
local Cost

local function CancelPlacement()
	Signal = Plane:disable(ItemObject)
	if workspace:WaitForChild(ItemName) then
		CancelPlacement()
		workspace[ItemName]:Destroy()
	end
	if PrevItem then
		if workspace:WaitForChild(PrevItem) then
			CancelPlacement()
			workspace[PrevItem]:Destroy()
		end
	end
	if (ItemName) then
--		if workspace:FindFirstChild(ItemObject.Name) then
--			workspace:FindFirstChild(ItemObject.Name):Destroy()
--		end
--		if ItemObject.Parent then
----			Plane:disable(ItemObject)
--			ItemObject:Destroy()
--		end
--		if ItemObject then
----			Plane:disable(ItemObject)
--			ItemObject:Destroy()
--		end
		game.Workspace:FindFirstChild(ItemName):Destroy()
		ItemObject = nil
		Signal = nil
		ItemName = nil
	end
end

local function iniciatePlacemnt(ItemName)
	if workspace:FindFirstChild(ItemName) then
		CancelPlacement()
		workspace[ItemName]:Destroy()
	end
	if PrevItem then
		if workspace:FindFirstChild(PrevItem) then
			CancelPlacement()
			workspace[PrevItem]:Destroy()
		end
	end
--	CancelPlacement()
	script.Parent.Frame.Visible = false
	local Item = Items:FindFirstChild(ItemName)
	ItemObject = Item:Clone()
	ItemName = ItemObject.Name
	PrevItem = ItemName
	
	for _, Object in pairs(ItemObject:GetChildren()) do
		if Object:IsA("BasePart") or Object:IsA("Part") then
			Object.CanCollide = false
		end
	end
	ItemObject.Parent = workspace
	Signal = Plane:enable(ItemObject)
	
	Signal:connect(function(location, _)
		if Player.leaderstats.Cash.Value >= Item.Cost.Value and _G.CheckInv(ItemName) then
			game:GetService("ReplicatedStorage").Events.ClientPlaced:FireServer(ItemName, location, Cost)
--			CancelPlacement()
		else
			Signal = Plane:disable(ItemObject)
			ItemObject:Destroy()
		end
	end)
end

UIS.InputBegan:Connect(function(key,gpe)
	if not gpe then
		if ItemObject then
			if key.KeyCode == Enum.KeyCode.X then
				Signal = Plane:disable(ItemObject)
				ItemObject:Destroy()
			end
		end
	end
end)

for i,v in pairs(script.Parent.Background:GetDescendants()) do
	if v:IsA("ImageButton") then
		v.MouseButton1Click:Connect(function()
			if _G.CheckInv(v.Item.Value) then
				iniciatePlacemnt(v.Item.Value)
			end
		end)
	end
end

1 comment

0

Errors? Line number for where you think it might be broken? Too much to work with mate.