Item in build mode not placing

Hello, I am Kevman599! Lately I have been working on making a build mode in roblox studio, I am currently trying to make items placeable in build mode, I already have the paths, walls implemented. But Whenever I try to place this ModernFridge in it, it appears when you click the button for it which just says item for now, then when it appears you can drag it and stuff inside the grid, but when you click to place it, it dissapears 100% of the time. Example of it here : scoobydude96-gmail I need it to place down on the grid when I click it, the script that is currently being used is down below, the error when clicking the button to place the fridge appeared this.

How can I fix the script?
Script

local Tycoons = workspace.TycoonHolder
local Event = game:GetService("ReplicatedStorage").Event
local Functions = require(game:GetService("ReplicatedStorage").Modules.TycoonFunctions)
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestPhase2", "global")
local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Player)
	local Tycoon = Functions.GetAvalibleTycoon()
	if Tycoon then
		local Info = Tycoon.Info
		Info.Owner.Value = Player
		Tycoon.OwnerPart.BillboardGui.TextLabel.Text = Player.Name.."'s Plot!"
		
		wait(3)
		Functions.LoadTycoon(Player)
	end
end)

Event.OnServerEvent:connect(function(Player, Request, ...)
if Player then
	if Request then
		local Mouse = Player:GetMouse()
		local Args = {...}
		if Request == "sdgfhfgjsdhgdflkbdgdfhfghghorsih4go4sdhgfhdafgidghdidfhigdfighdfuigushdhfisdiggibsgufdnbdifughsuidfidfdgfgfghfdgg" then
			local Tycoon = Functions.GetTycoonFromPlayer(Player)
			for i, v in pairs(Tycoon.EditingWalls:GetDescendants()) do
				if v:IsA("Decal") then
					spawn(function()
						for i = 1,0,-0.01 do
							v.Transparency = i
							wait()
						end
					end)
				elseif v:IsA("BasePart") then
					v.CanCollide = true
				end
			end
		elseif Request == "sdgdifugdfiughUIFDIGDFUIhuhgidfhiiHIIUhIHihhuiUHHUIhhhuidfgdnnbdsdfeiojsgnsdngiilliillllliooigniosdngnxzhhbBbIBBoiill" then
			DataStore:SetAsync(""..Player.UserId.."", Args[1])
		elseif Request == "sdgdifugdfiughUIFDIdgfdIhuhgidfhiiHIIUhIHihhuiUHHUIhhhuidfgdnnbdsdfeiojsgnsdngiillIllillllliooignggjbdngnxzhhbBbIBBoiill" then
			return DataStore:GetAsync(""..Player.UserId.."_")
		elseif Request == "fgdfhguiUHOHFOHDHOIHOHioobndofigiodhtodfoidfbhhiosngodfihIGHIHFIHTdfgdfhfbfdIIlllIIIddfsIIll434DSOIJGJIBILLllII" then
			if Args[1] == "Wall" then
				if Args[2] and Args[3] then
					local Tycoon = Functions.GetTycoonFromPlayer(Player)
					if Tycoon then
						local Model = Instance.new("Model")
						Model.Name = "Wall"
						local WallPart = Instance.new("Part", Model)
						WallPart.Anchored = true
						WallPart.Transparency = 1
						WallPart.Material = Enum.Material.SmoothPlastic
						WallPart.Name = "Hitbox"
						WallPart.Size = Vector3.new(9, 12, 0.4)
						local Pole1 = Instance.new("Part", Model)
						Pole1.Shape = "Cylinder"
						Pole1.Name = "Pole1"
						Pole1.Anchored = true
						Pole1.Transparency = 0
						Pole1.Material = Enum.Material.SmoothPlastic
						Pole1.Size = Vector3.new(9, 0.4, 0.4)
						Pole1.CFrame = Args[2]
						local Pole2 = Instance.new("Part", Model)
						Pole2.Shape = "Cylinder"
						Pole2.Name = "Pole2"
						Pole2.Anchored = true
						Pole2.Transparency = 0
						Pole2.Material = Enum.Material.SmoothPlastic
						Pole2.Orientation = Vector3.new(0,0,math.rad(90))
						Pole2.Size = Vector3.new(9, 0.4, 0.4)
						Pole2.CFrame = Args[3]
						WallPart.Size = Vector3.new((Pole1.Position - Pole2.Position).Magnitude,9,0.4)
						WallPart.CFrame = CFrame.new(
						Pole1.Position + 0.5*(Pole2.Position - Pole1.Position),
						Pole1.Position + 0.5*(Pole2.Position - Pole1.Position) + (Pole1.Position - Pole2.Position).Unit:Cross(Vector3.new(0,1,0))
						)
						local WallPart3 = Instance.new("Part", Model)
						WallPart3.Anchored = true
						WallPart3.Transparency = 0
						WallPart3.Material = Enum.Material.SmoothPlastic
						WallPart3.Name = "Wall1"
						WallPart3.Orientation = Vector3.new(0,0,math.rad(90))
						WallPart3.Size = WallPart.Size - Vector3.new(0,0,(WallPart.Size.Z/2))
						WallPart3.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * 0.1
						local WallPart4 = Instance.new("Part", Model)
						WallPart4.Anchored = true
						WallPart4.Transparency = 0
						WallPart4.Material = Enum.Material.SmoothPlastic
						WallPart4.Name = "Wall2"
						WallPart4.Orientation = Vector3.new(0,0,math.rad(90))
						WallPart4.Size = WallPart.Size - Vector3.new(0,0,(WallPart.Size.Z/2))
						WallPart4.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * -0.1
						Model.PrimaryPart = WallPart
						Model.Parent = Tycoon.Purchases.Walls
					end
				end
			elseif Args[1] == "Path" then
				if Args[2] and Args[3] then
					local Tycoon = Functions.GetTycoonFromPlayer(Player)
					if Tycoon then
							local Model = Instance.new("Model")
							Model.Name = "Path"
							local WallPart = Instance.new("Part", Model)
							WallPart.Anchored = true
							WallPart.Transparency = 0
							WallPart.Material = Enum.Material.SmoothPlastic
							WallPart.Name = "Hitbox"
							WallPart.Size = Vector3.new(0.2, 3, 3)
							local Pole1 = Instance.new("Part", Model)
							Pole1.Shape = "Cylinder"
							Pole1.Name = "Pole1"
							Pole1.Anchored = true
							Pole1.Transparency = 0
							Pole1.Material = Enum.Material.SmoothPlastic
							Pole1.Size = Vector3.new(0.2, 3, 3)
							Pole1.CFrame = Args[2]
							local Pole2 = Instance.new("Part", Model)
							Pole2.Shape = "Cylinder"
							Pole2.Name = "Pole2"
							Pole2.Anchored = true
							Pole2.Transparency = 0
							Pole2.Material = Enum.Material.SmoothPlastic
							Pole2.Orientation = Vector3.new(0,0,math.rad(90))
							Pole2.Size = Vector3.new(0.2, 3, 3)
							Pole2.CFrame = Args[3]
							WallPart.Size = Vector3.new((Pole1.Position - Pole2.Position).Magnitude,0.2,3)
							WallPart.CFrame = CFrame.new(
								Pole1.Position + 0.5*(Pole2.Position - Pole1.Position),
								Pole1.Position + 0.5*(Pole2.Position - Pole1.Position) + (Pole1.Position - Pole2.Position).Unit:Cross(Vector3.new(0,1,0))
							)
							Model.PrimaryPart = WallPart
							Model.Parent = Tycoon.Purchases.Paths
						end
					end
				elseif Args[1]:IsA("Model") then
					local Pos = Mouse.Hit.p
					local Clone = game.ReplicatedStorage.ItemHolder:FindFirstChild(Args[1].Name):Clone()
					Clone:SetPrimaryPartCFrame(CFrame.new(Pos+Vector3.new(0,(Clone.PrimaryPart.Size.Y/2),0)))
					Clone.Parent = Functions.GetTycoonFromPlayer(Player).Purchases
				end
			end
		end
	end
end)
local Tycoons = workspace.TycoonHolder
local Event = game:GetService("ReplicatedStorage").Event
local Functions = require(game:GetService("ReplicatedStorage").Modules.TycoonFunctions)
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestPhase2", "global")
local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Player)
	local Tycoon = Functions.GetAvalibleTycoon()
	if Tycoon then
		local Info = Tycoon.Info
		Info.Owner.Value = Player
		Tycoon.OwnerPart.BillboardGui.TextLabel.Text = Player.Name.."'s Plot!"
		
		wait(3)
		Functions.LoadTycoon(Player)
	end
end)

Event.OnServerEvent:connect(function(Player, Request, ...)
if Player then
	if Request then
		local Mouse = Player:GetMouse()
		local Args = {...}
		if Request == "sdgfhfgjsdhgdflkbdgdfhfghghorsih4go4sdhgfhdafgidghdidfhigdfighdfuigushdhfisdiggibsgufdnbdifughsuidfidfdgfgfghfdgg" then
			local Tycoon = Functions.GetTycoonFromPlayer(Player)
			for i, v in pairs(Tycoon.EditingWalls:GetDescendants()) do
				if v:IsA("Decal") then
					spawn(function()
						for i = 1,0,-0.01 do
							v.Transparency = i
							wait()
						end
					end)
				elseif v:IsA("BasePart") then
					v.CanCollide = true
				end
			end
		elseif Request == "sdgdifugdfiughUIFDIGDFUIhuhgidfhiiHIIUhIHihhuiUHHUIhhhuidfgdnnbdsdfeiojsgnsdngiilliillllliooigniosdngnxzhhbBbIBBoiill" then
			DataStore:SetAsync(""..Player.UserId.."", Args[1])
		elseif Request == "sdgdifugdfiughUIFDIdgfdIhuhgidfhiiHIIUhIHihhuiUHHUIhhhuidfgdnnbdsdfeiojsgnsdngiillIllillllliooignggjbdngnxzhhbBbIBBoiill" then
			return DataStore:GetAsync(""..Player.UserId.."_")
		elseif Request == "fgdfhguiUHOHFOHDHOIHOHioobndofigiodhtodfoidfbhhiosngodfihIGHIHFIHTdfgdfhfbfdIIlllIIIddfsIIll434DSOIJGJIBILLllII" then
			if Args[1] == "Wall" then
				if Args[2] and Args[3] then
					local Tycoon = Functions.GetTycoonFromPlayer(Player)
					if Tycoon then
						local Model = Instance.new("Model")
						Model.Name = "Wall"
						local WallPart = Instance.new("Part", Model)
						WallPart.Anchored = true
						WallPart.Transparency = 1
						WallPart.Material = Enum.Material.SmoothPlastic
						WallPart.Name = "Hitbox"
						WallPart.Size = Vector3.new(9, 12, 0.4)
						local Pole1 = Instance.new("Part", Model)
						Pole1.Shape = "Cylinder"
						Pole1.Name = "Pole1"
						Pole1.Anchored = true
						Pole1.Transparency = 0
						Pole1.Material = Enum.Material.SmoothPlastic
						Pole1.Size = Vector3.new(9, 0.4, 0.4)
						Pole1.CFrame = Args[2]
						local Pole2 = Instance.new("Part", Model)
						Pole2.Shape = "Cylinder"
						Pole2.Name = "Pole2"
						Pole2.Anchored = true
						Pole2.Transparency = 0
						Pole2.Material = Enum.Material.SmoothPlastic
						Pole2.Orientation = Vector3.new(0,0,math.rad(90))
						Pole2.Size = Vector3.new(9, 0.4, 0.4)
						Pole2.CFrame = Args[3]
						WallPart.Size = Vector3.new((Pole1.Position - Pole2.Position).Magnitude,9,0.4)
						WallPart.CFrame = CFrame.new(
						Pole1.Position + 0.5*(Pole2.Position - Pole1.Position),
						Pole1.Position + 0.5*(Pole2.Position - Pole1.Position) + (Pole1.Position - Pole2.Position).Unit:Cross(Vector3.new(0,1,0))
						)
						local WallPart3 = Instance.new("Part", Model)
						WallPart3.Anchored = true
						WallPart3.Transparency = 0
						WallPart3.Material = Enum.Material.SmoothPlastic
						WallPart3.Name = "Wall1"
						WallPart3.Orientation = Vector3.new(0,0,math.rad(90))
						WallPart3.Size = WallPart.Size - Vector3.new(0,0,(WallPart.Size.Z/2))
						WallPart3.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * 0.1
						local WallPart4 = Instance.new("Part", Model)
						WallPart4.Anchored = true
						WallPart4.Transparency = 0
						WallPart4.Material = Enum.Material.SmoothPlastic
						WallPart4.Name = "Wall2"
						WallPart4.Orientation = Vector3.new(0,0,math.rad(90))
						WallPart4.Size = WallPart.Size - Vector3.new(0,0,(WallPart.Size.Z/2))
						WallPart4.CFrame = WallPart.CFrame + WallPart.CFrame.lookVector * -0.1
						Model.PrimaryPart = WallPart
						Model.Parent = Tycoon.Purchases.Walls
					end
				end
			elseif Args[1] == "Path" then
				if Args[2] and Args[3] then
					local Tycoon = Functions.GetTycoonFromPlayer(Player)
					if Tycoon then
							local Model = Instance.new("Model")
							Model.Name = "Path"
							local WallPart = Instance.new("Part", Model)
							WallPart.Anchored = true
							WallPart.Transparency = 0
							WallPart.Material = Enum.Material.SmoothPlastic
							WallPart.Name = "Hitbox"
							WallPart.Size = Vector3.new(0.2, 3, 3)
							local Pole1 = Instance.new("Part", Model)
							Pole1.Shape = "Cylinder"
							Pole1.Name = "Pole1"
							Pole1.Anchored = true
							Pole1.Transparency = 0
							Pole1.Material = Enum.Material.SmoothPlastic
							Pole1.Size = Vector3.new(0.2, 3, 3)
							Pole1.CFrame = Args[2]
							local Pole2 = Instance.new("Part", Model)
							Pole2.Shape = "Cylinder"
							Pole2.Name = "Pole2"
							Pole2.Anchored = true
							Pole2.Transparency = 0
							Pole2.Material = Enum.Material.SmoothPlastic
							Pole2.Orientation = Vector3.new(0,0,math.rad(90))
							Pole2.Size = Vector3.new(0.2, 3, 3)
							Pole2.CFrame = Args[3]
							WallPart.Size = Vector3.new((Pole1.Position - Pole2.Position).Magnitude,0.2,3)
							WallPart.CFrame = CFrame.new(
								Pole1.Position + 0.5*(Pole2.Position - Pole1.Position),
								Pole1.Position + 0.5*(Pole2.Position - Pole1.Position) + (Pole1.Position - Pole2.Position).Unit:Cross(Vector3.new(0,1,0))
							)
							Model.PrimaryPart = WallPart
							Model.Parent = Tycoon.Purchases.Paths
						end
					end
				elseif Args[1]:IsA("Model") then
					local Pos = Mouse.Hit.p
					local Clone = game.ReplicatedStorage.ItemHolder:FindFirstChild(Args[1].Name):Clone()
					Clone:SetPrimaryPartCFrame(CFrame.new(Pos+Vector3.new(0,(Clone.PrimaryPart.Size.Y/2),0)))
					Clone.Parent = Functions.GetTycoonFromPlayer(Player).Purchases
				end
			end
		end
	end
end)

I think to prevent an error in this code, you have to check if Args[1] exists first and then checking if Args[1] is a Model.

How would I do that? I am still a learner.

1 Like

If you go to line 135, change the elseif statement to “elseif Args[1] then” and add an “if” statement saying “if Args[1]:IsA(“Model”) then” with that code inside. Make sure to add an extra “end”