Problems with clone of a model in ReplicatedStorage?
I have a button that, when clicked, clones a model from ReplicatedStorage. The clone follows the player's cursor and locks to a grid area. When a certain part of the model is clicked, it is locked into position and no longer follows the cursor.
01 | local mouse = game.Players.LocalPlayer:GetMouse() |
02 | local testdesk = game.ReplicatedStorage.TestDesk:Clone() |
04 | game:GetService( "UserInputService" ).InputBegan:connect( function (inputObject) |
05 | if inputObject.KeyCode = = Enum.KeyCode.R and script.Parent.Rotate.Value = = false then |
06 | script.Parent.Rotate.Value = true |
07 | elseif inputObject.KeyCode = = Enum.KeyCode.R and script.Parent.Rotate.Value = = true then |
08 | script.Parent.Rotate.Value = false |
09 | elseif inputObject.KeyCode = = Enum.KeyCode.LeftShift or inputObject.KeyCode = = Enum.KeyCode.RightShift then |
10 | script.Parent.Parent.Parent.Cancel.Visible = false |
12 | script.Parent.Parent.Parent.Active.Value = false |
16 | script.Parent.MouseButton 1 Down:connect( function () |
17 | if script.Parent.Parent.Parent.Active.Value = = false then |
18 | script.Parent.Parent.Parent.Active.Value = true |
19 | script.Parent.Parent.Parent.Cancel.Visible = true |
20 | testdesk.Parent = workspace |
21 | testdesk.PrimaryPart = testdesk.Primary |
22 | for i,v in pairs (testdesk:GetChildren()) do |
23 | if v.Name ~ = "Primary" then |
28 | while script.Parent.Parent.Parent.Active.Value = = true do |
29 | if mouse.Target ~ = nil then |
30 | if mouse.Target.Name = = "Even" and mouse.Target.Parent ~ = testdesk and script.Parent.Rotate.Value = = true then |
31 | testdesk:SetPrimaryPartCFrame(mouse.Target.CFrame * CFrame.Angles( 0 , math.pi/ 2 , 0 )) |
32 | elseif mouse.Target.Name = = "Even" and mouse.Target.Parent ~ = testdesk and script.Parent.Rotate.Value = = false then |
33 | testdesk:SetPrimaryPartCFrame(mouse.Target.CFrame * CFrame.Angles( 0 , 0 , 0 )) |
41 | script.Parent.Rotate.Changed:connect( function () |
43 | testdesk:SetPrimaryPartCFrame(testdesk.Primary.CFrame * CFrame.Angles( 0 , math.pi/ 2 , 0 )) |
46 | script.Parent.Parent.Parent.Cancel.MouseButton 1 Down:connect( function () |
47 | script.Parent.Parent.Parent.Cancel.Visible = false |
49 | script.Parent.Parent.Parent.Active.Value = false |
52 | testdesk.Primary.ClickDetector.MouseClick:connect( function () |
53 | if script.Parent.Parent.Parent.Active.Value = = true then |
54 | script.Parent.Parent.Parent.Cancel.Visible = false |
55 | script.Parent.Visible = false |
56 | script.Parent.Parent.Parent.Active.Value = false |
57 | for i,v in pairs (testdesk:GetChildren()) do |
58 | if v.Name ~ = "Primary" then |
59 | v.Transparency = game.ReplicatedStorage.TestDesk:FindFirstChild(v.Name).Transparency |
61 | else v.Transparency = 1 |
Here's what the GUI and the model look like:
The problem here is that since the clone of the model is determined before any events occur, which means that only one clone of the model can exist at any given time. Eventually I will make a script that will allow the player to place multiple desks or other models, and this clone problem is going to make that impossible. How can I fix this without ruining my script?