Me and a friend are making a City Life type game and im making the placement system but there's a bug in it, when i go to place something it works but then it stops after the first time here is my code:
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Item = "Chair" local Cost = 0 local Object = game.Lighting.Ownables:FindFirstChild(Item) script.Parent.MouseButton1Click:connect(function() local Fold2 = game.Workspace:FindFirstChild(Player.Name.."Folder") if Fold2 == nil then print("Folder not found, creating one") local Fold = Instance.new("Folder",workspace) local PartG = Object:Clone() local Part = PartG Fold.Name = Player.Name.."Folder" PartG.Name = "UnPlaced" PartG.Parent = Fold else print("Theres already a folder, so just creating a part") local PartG = Object:Clone() local Part = PartG PartG.Name = "UnPlaced" PartG.Parent = game.Workspace:FindFirstChild(Player.Name.."Folder") end end) Mouse.Move:connect(function() if Mouse.Target.Name == "Grid" then print("The target is a grid!") local Folder = workspace:FindFirstChild(Player.Name.."Folder") if Folder then print("Found the folder!") local Part = Folder:FindFirstChild("UnPlaced") if Part then if Mouse.Target.Parent.Parent.Owner.Value == game.Players.LocalPlayer.Name then print("Found the part") Part.Position = Mouse.Target.Position Part.Anchored = true Part.CanCollide = false Part.Transparency = .5 Mouse.Button1Down:connect(function() local Fold = game.Workspace:FindFirstChild(Player.Name.."PlacedParts") if Fold == nil then print("Mouse button 1 was clicked") local Fold2 = Instance.new("Folder",workspace) Fold2.Name = Player.Name.."PlacedParts" local PlacingPart = Fold2:FindFirstChild(Player.Name.."Part") if PlacingPart == nil then Part.Parent = Fold2 Part.Anchored = true Part.CanCollide = true Part.Transparency = 0 wait(1) Part.Name = Player.Name.."Part" else local PlacingPart = Fold2:FindFirstChild(Player.Name.."Part") if PlacingPart == nil then Part.Parent = Fold Part.Anchored = true Part.CanCollide = true Part.Transparency = 0 wait(1) Part.Name = Player.Name.."Part" end end end end) Mouse.KeyDown:connect(function(key) if key == "r" then print("The R key was pressed!") local Fold = game.Workspace:FindFirstChild(Player.Name.."PlacedParts") if Fold then print("Folder was found") local Part = Fold:findFirstChild("Unplaced") if Part then print("Part was found") Part.Rotation = Part.Rotation + Vector3.new(0,15,0) end end end end) Mouse.KeyDown:connect(function(key) if key == "x" then print("The X key was pressed!") local Fold = game.Workspace:FindFirstChild(Player.Name.."Folder") if Fold then print("Folder was found") local Part = Fold:findFirstChild("Unplaced") print(2) if Part then print(1) Part:Destroy() end end end end) end end end else print("") end end) --[[Mouse.Button1Down:connect(function() print("Mouse was clicked") if Mouse.Target.Name == Player.Name.."Part" then local Part = Mouse.Target local Fold = game.Workspace:FindFirstChild(Player.Name.."Folder") if Fold then local Hasp = Fold:FindFirstChild("UnPlaced") if Hasp == nil then Part.Parent = Fold Part.Name = "UnPlaced" end end end end)--]]
I think you have to many information in just one script and btw do not use just key = "x", do key "x" and "X" so if the player has caps lock on for any reason he can still acced to it