[SOLVED] Script not fully working, unable to locate issue

Hello Developers! :wave:

(This is my first topic creation, so please excuse any mistakes! :smiling_face:)

In the past few days, I have been trying to learn how to script, and create simple functions using scripts, which has been going somewhat well. My main goal is to create a roleplay facility game for my own benefit in a private roleplay group. One of the many tasks of making a roleplaying game is to create placeable items, which is something I do not have the knowledge of making on my own.

I’ve made the decision of looking at how to make it online, using different online resources, which hasn’t been going very well at least. I have been trying multiple methods, tutorials and resources, and not a single one has worked out fully.

The one that has been the closest to success is one I found online. I’ll provide the steps of said source here. This is where I require feedback & support. I am unable to locate where an issue may be, so I am reaching out to more experienced developers/scripters for assistance.

Steps/Additions made/added to create said “placement system”:
- Setup #1 (Object Folder)
Object Folder with placeables.

- Setup #2 (ServerScriptService “Placement-Server”)

local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("ObjectFolder")

PlacementEvent.OnServerEvent:Connect(function(Player, PreviewObject, ObjectCFrame)
	
	local Object = ObjectFolder:FindFirstChild(PreviewObject):Clone()
	
	Object.SetPrimaryPartCFrame(ObjectCFrame)
	Object.Parent = game.Workspace
end)

- Setup #3 (GUI and LocalScript “Placement-Handler”)
image

local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("ObjectFolder")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()

local Frame = script.Parent:WaitForChild("Frame")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local PlacingObject = false
local RotatingObject = false

for i, Button in pairs(Frame:GetChildren()) do


	if Button:IsA("TextButton") then

		Button.MouseButton1Click:Connect(function()

			if PlacingObject  == false then

				PlacingObject = true
				Frame.Visible = false

				local RotationAmount = 0

				local PreviewObject = ObjectFolder:FindFirstChild(Button.Name):Clone()
				PreviewObject.Parent = game.Workspace

				for i, Parts in pairs(PreviewObject:GetDescendants()) do

					if Parts:IsA("BasePart") then

						Parts.Transparency = .5
						Parts.CanCollide = false
					end
				end

				UserInputService.InputBegan:Connect(function(Key, GameProcessed)

					if not GameProcessed then

						if Key.KeyCode == Enum.KeyCode.R then

							RotatingObject = true

							while RotatingObject == true do 
								wait()
								RotationAmount += 2								
							end							
						end						
					end					
				end)

				UserInputService.InputEnded:Connect(function(Key)

					if Key.KeyCode == Enum.KeyCode.R then

						RotatingObject = false

					end
				end)

				RunService.RenderStepped:Connect(function()

					if PlacingObject == true then

						Mouse.TargetFilter = PreviewObject

						if PreviewObject:FindFirstChild("MainPart") then

							local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X, Mouse.Hit.Position.Y + PreviewObject.PrimaryPart.Size.Y/2, Mouse.Hit.Position.Z)
							local ObjectAngles = CFrame.Angles(0, math.rad(RotationAmount), 0)

							PreviewObject:SetPrimaryPartCFrame(ObjectCFrame * ObjectAngles)
						end
					end
				end)

				Mouse.Button1Up:Connect(function()

					if PlacingObject == true then

						PlacingObject = false

						PlacementEvent:FireServer(PreviewObject.Name, PreviewObject.PrimaryPart.CFrame)

						Frame.Visible = true
						PreviewObject:Destroy()	
					end
				end)
			end
		end)
	end
end

- Setup #4 (Event)
image

So this is the basic outline of what the tutorial asked me to follow/recreate. As I mentioned before, the GUI works, clicking a button hides it and places the Outline Part and the placeable on to your mouse, but when you click, everything disappears, and the GUI returns to a normal state.

I’ve tried digging into the script, but my little scripting knowledge did not help, so I came here to look after experienced support!

Any kind of assistance and support would be very appreciated, and if you have any other things I should improve on the above, please let me know!

-Thank you! :wink:

1 Like

In Setup #2, it should be

Object:SetPrimaryPartCFrame(ObjectCFrame)

instead of

Object.SetPrimaryPartCFrame(ObjectCFrame)

Do you have the output window open? It’ll print out errors and help you diagnose what went wrong in your scripts usually.

EDIT: One other thing to point out, :SetPrimaryPartCFrame has been superseded by :PivotTo so you should use that instead.

Here’s what the wiki says:

This function has been superseded by PVInstance:PivotTo which acts as a more performant replacement and does not change your code’s behavior. Use PVInstance:PivotTo for new work and migrate your existing Model:SetPrimaryPartCFrame calls when convenient.

1 Like

I will make sure to fix the issues you have pointed out right now, thanks!

The output window was uh, questionably packed with many other outputs and I couldn’t really point out anything :sweat_smile:

1 Like

My my, this indeed has worked!

I have made the changes, and everything works flawlessly! Thank you very much for responding and helping me, very much appreciated!

Have a great day! :smile: :hearts:

1 Like