Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local furnitureFolder = game.ReplicatedStorage:WaitForChild("Furniture")
- local re = game.ReplicatedStorage:WaitForChild("PlaceFurnitureRE")
- local chosenFurniture = nil
- function handleFurniture(furniture)
- local btn = script:WaitForChild("FurnitureButton"):Clone()
- btn.FurnitureName.Text = furniture.Name
- local furnitureClone = furniture:Clone()
- furnitureClone.Parent = btn.FurnitureImage
- local cam = Instance.new("Camera")
- btn.FurnitureImage.CurrentCamera = cam
- cam.Parent = btn.FurnitureImage
- cam.CFrame = CFrame.new(furnitureClone.PrimaryPart.Position + Vector3.new(5, 5, 5), furnitureClone.PrimaryPart.Position)
- btn.Parent = script.Parent
- btn.MouseButton1Click:Connect(function()
- chosenFurniture = furniture
- end)
- end
- for i, furniture in pairs(furnitureFolder:GetChildren()) do
- handleFurniture(furniture)
- end
- furnitureFolder.ChildAdded:Connect(handleFurniture)
- local mouse = game.Players.LocalPlayer:GetMouse()
- local isPlacing = false
- mouse.Button1Down:Connect(function()
- isPlacing = true
- end)
- mouse.Button1Up:Connect(function()
- isPlacing = false
- end)
- local isRemoving = false
- mouse.Button2Down:Connect(function()
- isRemoving = true
- end)
- mouse.Button2Up:Connect(function()
- isRemoving = false
- end)
- local rotating = false
- local rotation = 0
- game:GetService("UserInputService").InputBegan:Connect(function(inp)
- if inp.KeyCode == Enum.KeyCode.R then
- rotating = true
- end
- end)
- game:GetService("UserInputService").InputEnded:Connect(function(inp)
- if inp.KeyCode == Enum.KeyCode.R then
- rotating = false
- end
- end)
- local ghostItem = nil
- while wait() do
- if ghostItem then ghostItem:Destroy() end
- local hit = mouse.Hit
- local target = mouse.Target
- if rotating then rotation += 0.1 end
- if hit and chosenFurniture and mouse.Target and mouse.Target.Name == "Plot" then
- ghostItem = chosenFurniture:Clone()
- for i, d in pairs(ghostItem:GetDescendants()) do
- if d:IsA("BasePart") then d.Transparency = 0.7; d.CanCollide = false end
- end
- local ghostPos = hit.Position + Vector3.new(0, ghostItem.PrimaryPart.Size.Y/2, 0)
- local ghostRot = ghostItem.PrimaryPart.CFrame - ghostItem.PrimaryPart.Position
- ghostItem:SetPrimaryPartCFrame(CFrame.new(ghostPos) * ghostRot * CFrame.Angles(0, rotation, 0))
- ghostItem.Parent = workspace
- if isPlacing then
- re:FireServer(chosenFurniture, ghostItem.PrimaryPart.CFrame, true, target)
- end
- end
- if isRemoving then
- re:FireServer(mouse.Target)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement