You can write your topic however you want, but you need to answer these questions:
-
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. -
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. -
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:
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!