Help with my placement system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello everyone! I am trying to make a roblox local script for my gui, for a placement system, the script.Parent is a textButton, so whenever its pressed it places down a block.
  2. What is the issue? Include screenshots / videos if possible!
    Well, it places one model but not the other, despite having zero changes. ive altered both models and sometimes one works but the other does not regardless of which I place first. I am very stumped.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have searched placement systems, mouse position detection, but I cant find a solution, I even tried using AI to help fix it to no avail.
    Hierarchy of the builds:

image

External Media

as you can see, the mine works but the furnace doesnt. earlier when trying to fix it it was the furnace not working but the mine working. Im really confused.

local button = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local moveSpeed = 0.2 
local rotationStep = 1 

button.MouseButton1Down:Connect(function()
	if button.Visible then
		local item = script.Parent.Parent.Parent["Main Frame"].ScrollingFrame.SelectedItem.Value
		local aura = game.ReplicatedStorage.Buildings[item]:Clone()
		aura.Parent = game.Workspace
		aura.Name = "Clone"
		local primPart = aura:FindFirstChild("PrimPart")
		if not primPart then
			warn("PrimPart not found in aura")
			return
		end
		primPart.CFrame = CFrame.new()
		local part = primPart
		part.CFrame = CFrame.new(0, 0, 0)

		local moving = true
		local rotationAngle = 0
		local rotating = false

		local function movePart()
			while moving do
				aura.PrimPart.Transparency = 0
				local hit = mouse.Hit
				if hit then
					local targetCFrame = CFrame.new(hit.p)
					part.CFrame = part.CFrame:Lerp(targetCFrame, moveSpeed)
					part.CFrame = CFrame.new(part.CFrame.X, 48.29, part.CFrame.Z)
					part.Orientation = Vector3.new(0, rotationAngle, 0)

					local touchingCorrectPlate = false
					local touchingOtherObjects = false
					for _, obj in pairs(workspace:GetPartsInPart(part)) do
						if obj ~= part and not obj:IsDescendantOf(aura) and obj.Name ~= "Baseplate" then
							if player.Team == game.Teams["Red Team"] and obj.Name == "Redplate" then
								touchingCorrectPlate = true
							elseif player.Team == game.Teams["Blue Team"] and obj.Name == "Blueplate" then
								touchingCorrectPlate = true
							else
								touchingOtherObjects = true
							end
						end
					end

					if touchingCorrectPlate and not touchingOtherObjects then
						part.BrickColor = BrickColor.new("Bright green")
					else
						part.BrickColor = BrickColor.new("Bright red")
					end
				end
				runService.RenderStepped:Wait()
			end
		end

		mouse.Button1Down:Connect(function()
			local touchingCorrectPlate = false
			local touchingOtherObjects = false
			for _, obj in pairs(workspace:GetPartsInPart(part)) do
				if obj ~= part and not obj:IsDescendantOf(aura) and obj.Name ~= "Baseplate" then

					if player.Team == game.Teams["Red Team"] and obj.Name == "Redplate" then
						touchingCorrectPlate = true
					elseif player.Team == game.Teams["Blue Team"] and obj.Name == "Blueplate" then
						touchingCorrectPlate = true
					else
						touchingOtherObjects = true
					end
				end
			end

			if touchingCorrectPlate and not touchingOtherObjects then
				moving = false
				aura.PrimPart.Transparency = 1
				aura.PrimPart.CanCollide = true
				aura.PrimPart.CanTouch = true
				local plc = game.ReplicatedStorage:FindFirstChild("PlaceBlock")
				local namex = game.ReplicatedStorage.Buildings[item].Name
				local ab = aura:FindFirstChild("PrimPart")
				local posx = ab.Position.X
				local posy = ab.Position.Y
				local posz = ab.Position.Z
				local rotation = aura:FindFirstChild("PrimEx").Orientation.Y

				
				plc:FireServer(posx, posy, posz, namex, rotation)
				aura:Destroy()

			elseif touchingOtherObjects then
				print("touching other objects")
			else
				print("invalid placement")
			end
		end)
		userInputService.InputBegan:Connect(function(input, gameProcessed)
			if input.KeyCode == Enum.KeyCode.C and not gameProcessed and moving == true then
				if aura then
					aura:Destroy()
					moving = false
				end
			elseif input.KeyCode == Enum.KeyCode.R and not gameProcessed then
				rotating = true
				while rotating do
					rotationAngle = rotationAngle + rotationStep
					wait(0.1)  
				end
			end
		end)

		userInputService.InputEnded:Connect(function(input, gameProcessed)
			if input.KeyCode == Enum.KeyCode.R and not gameProcessed then
				rotating = false
				rotationAngle = 0
			end
		end)

		movePart()
	end
end)

Thank you all for reading!

2 Likes

Try this to show you if the items printed are what you expect:

    print("SelectedItem.Value = ", script.Parent.Parent.Parent["Main Frame"].ScrollingFrame.SelectedItem.Value)
    local item = script.Parent.Parent.Parent["Main Frame"].ScrollingFrame.SelectedItem.Value
    print("item name = ", item.Name)  
	local aura = game.ReplicatedStorage.Buildings[item]:Clone()

Seems to me you aren’t specifying which item in the Buildings folder you want correctly.

It didnt do anything sadly :frowning:
I think the issue is due to the way im detecting what parts touch what
image

as you can see it falsely detects stuff

1 Like

What is button a child of?
According to the GuiButton.MouseButton1Click documentation it should be a child of the GUIButton itself to fire.
You may also want to use GuiButton.MouseButton1Click

image
Its the “Place Button”
I think its just an issue with detection, im rewriting it
I wanted (for placement) it to click on anywhere on the screen and place it, similar to Miners Haven’s placement system

1 Like

I solved this by rewriting it. The issue was from a bad detection system overall, just down to how it was scripted.

1 Like