ROBLOX STUDIO - Служба пользовательского ввода зацикливается на InputBegan - PullRequest
0 голосов
/ 10 апреля 2020

Мой код работает по большей части, но когда он попадает в ту часть скрипта, которая ощущает левый щелчок по пространству мира, он остается в проверке, как если бы он был oop.

Это выходные данные

мой код:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local Structures = ReplicatedStorage:WaitForChild("Items")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local StructureFrame = script.Parent.InventoryFrame
local InventoryFolder = StructureFrame.ItemList
local char = player.Character or player.Character:Wait()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")

local mouse = player:GetMouse()
local maxPlacingDistance = 50
local rKeyIsPressed = false
local eKeyIsPressed = false
local placingStructure = false

for _, structureButton in pairs(InventoryFolder:GetChildren()) do
    if structureButton:IsA("ImageButton") then
        structureButton.MouseButton1Up:Connect(function()
            print(placingStructure)
            print("1 - START")
            StructureFrame.Visible = false

            local yOrientation = 0
            local goodToPlace = false
            local placedStructure
            if placingStructure == false then
                placingStructure = true
                print("2 - PLACING STRUCTURE = TRUE")
                local clientStructurePart = Structures:FindFirstChild(structureButton.Name):Clone()
                clientStructurePart.BrickColor = BrickColor.new("Forest green")
                clientStructurePart.Transparency = 0.6
                clientStructurePart.Material = "Neon"
                clientStructurePart.CanCollide = false
                clientStructurePart.Parent = game.Workspace

                local startingCFrame = CFrame.new(0, -2, -15)
                clientStructurePart.CFrame = HumanoidRootPart.CFrame:ToWorldSpace(startingCFrame)

                RunService.RenderStepped:Connect(function()
                    local mouseRay = mouse.UnitRay
                    local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)
                    local ignoreList = {clientStructurePart, char}
                    local hit, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList)

                    if hit and (HumanoidRootPart.Position - clientStructurePart.Position).Magnitude < maxPlacingDistance then
                        goodToPlace = true
                        clientStructurePart.BrickColor = BrickColor.new("Forest green")
                    else
                        goodToPlace = false
                        clientStructurePart.BrickColor = BrickColor.new("Crimson")
                    end

                    local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
                    local newCFrame = CFrame.new(position.X, position.Y + clientStructurePart.Size.Y/2, position.z)
                    clientStructurePart.CFrame = newCFrame * newAnglesCFrame
                end)

                UIS.InputBegan:Connect(function(input)
                    -- For constant rotation
                end)

                UIS.InputEnded:Connect(function(input)
                    if input.KeyCode == Enum.KeyCode.R then
                        rKeyIsPressed = true

                        local rotationSpeed = 15
                        if placingStructure == true then
                            yOrientation = yOrientation + rotationSpeed
                        end
                    end
                    if input.KeyCode == Enum.KeyCode.E then
                        local rotationSpeed = -15

                        eKeyIsPressed = true
                        if placingStructure == true then
                            yOrientation = yOrientation + rotationSpeed
                        end
                    end
                    if input.KeyCode == Enum.KeyCode.Q then
                        placingStructure = false
                        clientStructurePart:Destroy()
                        StructureFrame.Visible = true
                    end
                end)
                print("3 - FINISH")
                UIS.InputBegan:Connect(function(input)  --This is the one looping
                    if input.UserInputType == Enum.UserInputType.MouseButton1 then
                        if placingStructure == true then
                            if goodToPlace == true then
                                local StructureCFrame = clientStructurePart.CFrame
                                print(clientStructurePart.name)
                                placedStructure = PlaceStructure:InvokeServer(clientStructurePart.name, StructureCFrame)
                                if placedStructure == true then
                                    local placingStructure = false
                                    print("4 - PLACING STRUCTURE IS "..tostring(placingStructure))
                                    clientStructurePart:Destroy()
                                    StructureFrame.Visible = true
                                end
                            end
                        end
                    end

                end)
                print("5 - after the mouse click")
            else
                print("BREAK - placing structure is true")
            end
        end)
    end
end

Когда он проходит через в первый раз, РазмещениеStructure ложно; что позволяет ему проходить через основной блок оператора if. Вместо того, чтобы останавливаться на одном щелчке мыши, последняя функция появляется как al oop. Если кто-нибудь знает, почему это так, я был бы очень рад услышать от вас. Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...