What do you want to achieve? I want my script to end after i press the E button and the if statements are met.
What is the issue? The script doesnt go to the end and it causes problems.
What solutions have you tried so far? I tried to find solutions but they didnt work and i dont really know how to find the answers
CraftButton.MouseButton1Down:Connect(function()
BuildGui.Visible = true
local placedStructure
local yOrientation = 0
print("aaaa")
if placingStructure == false then
placingStructure = true
local clientStructure = structures:FindFirstChild(structureFrame.Name):Clone()
clientStructure.Parent = workspace
clientStructure.Name = "ClientStructure"
for _,part in pairs(clientStructure:GetChildren()) do
if part:IsA("BasePart") then
part.BrickColor = BrickColor.new("Forest green")
part.Material = "Neon"
part.Transparency = 0.25
part.CanCollide = false
end
end
yBuildingOffset = clientStructure.PrimaryPart.Size.Y/2
local event = RunService.RenderStepped:Connect(function()
local mouseRay = mouse.UnitRay
local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)
local ignoreList = {clientStructure, player.Character}
local hit, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList)
if hit and (hit:IsA("Terrain") or hit.Name == "Baseplate") and (player.Character.HumanoidRootPart.Position - position).Magnitude < maxPlacingDistance then
goodToPlace = true
for _,part in pairs(clientStructure:GetChildren()) do
if part:IsA("BasePart") then
part.BrickColor = BrickColor.new("Forest green")
end
end
else
goodToPlace = false
for _,part in pairs(clientStructure:GetChildren()) do
if part:IsA("BasePart") then
part.BrickColor = BrickColor.new("Crimson")
end
end
end
local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
local newCFrame = CFrame.new(position.X, position.Y + yBuildingOffset, position.Z)
clientStructure:SetPrimaryPartCFrame(newCFrame * newAnglesCFrame)
end)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
rKeyIsPressed = true
local rotationSpeed = 5
while rKeyIsPressed do
wait()
if placingStructure == true then
yOrientation = yOrientation + rotationSpeed
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
rKeyIsPressed = false
end
end)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if placingStructure == true then
if goodToPlace == true then
if clientStructure.PrimaryPart then
local StructureCFrame = clientStructure:GetPrimaryPartCFrame()
placedStructure = replicatedStorage.Events.PlaceStructure:InvokeServer(structureFrame.Name, StructureCFrame)
if placedStructure == true then
placingStructure = false
clientStructure:Destroy()
event:Disconnect()
goodToPlace = false
BuildGui.Visible = true
-- end functions
end
else
print("Failed to place structure")
end
end
end
end
end)
end
end)
-- go to here
You can EASILY compress your if statement into if input.KeyCode == Enum.KeyCode.E and placingStructure and goodToPlace then. When checking booleans, you don’t need to add an operator, you can just use the variable alone.
Anyways, do you have any errors in your log? Have you tried using breakpoints to see what the variables are at the breakpoint? (They’ll automatically pause the game and bring you to the script iirc)
Place a breakpoint at the point where it checks for clientStructure.PrimaryPart and check there.