Block in my block placement system is cloning when it's not supposed to. Why?
I have currently followed TheDevKing's tutorial of the block placement.
https://www.youtube.com/watch?v=hEqdq9VXfT4
The problem is, whenever I attempt to place this block, it always clones.
Why?
I may show you my scripts.
StarterGui > MainGui > StructureHandler (LocalScript)
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local PlacteStructure = ReplicatedStorage:WaitForChild( "PlaceStructure" ) |
03 | local Structures = ReplicatedStorage:WaitForChild( "Structures" ) |
05 | local UIS = game:GetService( "UserInputService" ) |
06 | local RunService = game:GetService( "RunService" ) |
08 | local player = game.Players.LocalPlayer |
09 | local StructureFrame = script.Parent.StructureFrame |
10 | local char = player.Character or player.CharacterAdded:Wait() |
11 | local HumanoidRootPart = char:WaitForChild( "HumanoidRootPart" ) |
13 | local mouse = player:GetMouse() |
15 | local yBuildingOffset = 1 |
16 | local maxPlacingDistance = 50 |
17 | local rKeyIsPressed = false |
18 | local placingStructure = false |
20 | for _, structureButton in pairs (StructureFrame:GetChildren()) do |
21 | if structureButton:IsA( "TextButton" ) then |
22 | structureButton.MouseButton 1 Up:Connect( function () |
24 | StructureFrame.Visible = false |
26 | local yOrientation = 0 |
27 | local goodToPlace = false |
30 | if placingStructure = = false then |
31 | placingStructure = true |
33 | local clientStructure = Structures:FindFirstChild(structureButton.Name):Clone() |
34 | clientStructure.BrickColor = BrickColor.new( "Forest green" ) |
35 | clientStructure.Material = "Neon" |
36 | clientStructure.CanCollide = false |
37 | clientStructure.Parent = workspace |
39 | local startingCFrame = CFrame.new( 0 , - 2 , - 15 ) |
40 | clientStructure.CFrame = HumanoidRootPart.CFrame:ToWorldSpace(startingCFrame) |
42 | RunService.RenderStepped:Connect( function () |
43 | local mouseRay = mouse.UnitRay |
44 | local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000 ) |
45 | local ignoreList = { clientStructure, char } |
46 | local hit, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList) |
48 | if hit and (HumanoidRootPart.Position - clientStructure.Position).Magnitude < maxPlacingDistance then |
50 | clientStructure.BrickColor = BrickColor.new( "Medium stone grey" ) |
53 | clientStructure.BrickColor = BrickColor.new( "Crimson" ) |
56 | local newAnglesCFrame = CFrame.Angles( 0 , math.rad(yOrientation), 0 ) |
57 | local newCFrame = CFrame.new(position.X, position.Y + yBuildingOffset, position.Z) |
58 | clientStructure.CFrame = newCFrame * newAnglesCFrame |
60 | UIS.InputBegan:Connect( function (input) |
61 | if input.KeyCode = = Enum.KeyCode.R then |
64 | local rotationSpeed = 5 |
65 | while rKeyIsPressed do |
67 | if placingStructure = = true then |
68 | yOrientation = yOrientation + rotationSpeed |
74 | UIS.InputEnded:Connect( function (input) |
75 | if input.KeyCode = = Enum.KeyCode.R then |
79 | UIS.InputBegan:Connect( function (input) |
80 | if input.UserInputType = = Enum.UserInputType.MouseButton 1 then |
81 | if placingStructure = = true then |
82 | if goodToPlace = = true then |
83 | local StructureCFrame = clientStructure.CFrame |
84 | placedStructure = PlacteStructure:InvokeServer(clientStructure.Name, StructureCFrame) |
86 | if placedStructure = = true then |
87 | placingStructure = false |
88 | clientStructure:Destroy() |
89 | StructureFrame.Visible = true |
ServerScriptService > RemoteHandler (ServerScript)
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local PlacteStructure = ReplicatedStorage:WaitForChild( "PlaceStructure" ) |
03 | local Structures = ReplicatedStorage:WaitForChild( "Structures" ) |
05 | PlacteStructure.OnServerInvoke = function (player, StructureName, StructureCFrame) |
07 | local realStructure = Structures:FindFirstChild(StructureName):Clone() |
10 | realStructure.CFrame = StructureCFrame |
11 | realStructure.Parent = workspace |