Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-08-06· OpenAIAi2 WildChat-4.8M (AI2)

скрипт не работает,что делать local workspace = game:GetService("Workspace") local…

  1. User

    скрипт не работает,что делать local workspace = game:GetService("Workspace") local TestPrompt = workspace.DialoguePrompts.TestPrompt local ProximityPrompt = TestPrompt.ProximityPrompt local Rig = workspace.Rig local TargetPart = workspace.TargetPart local LookPart = workspace.LookPart local function moveToTarget() local humanoid = Rig:FindFirstChildOfClass("Humanoid") if humanoid then humanoid:MoveTo(TargetPart.Position) humanoid.MoveToFinished:Connect(function() local lookVector = (LookPart.Position - Rig.PrimaryPart.Position).unit Rig:SetPrimaryPartCFrame(CFrame.new(Rig.PrimaryPart.Position, Rig.PrimaryPart.Position + lookVector)) end) end end local playerMoving = false -- Event to check if player is moving game:GetService("Players").PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local human = character:WaitForChild("Humanoid") human.Running:Connect(function(speed) playerMoving = speed > 0 end) end) end) ProximityPrompt.Triggered:Connect(function() if playerMoving then moveToTarget() else warn("Player is not moving.") end end)

  2. Assistant

    To diagnose why your script isn't working, I'll suggest some potential issues and solutions. Let's break down your script step by step and see where the issue might lie.

    1. Initial Setup:

      • Ensure that all path references like workspace.DialoguePrompts.TestPrompt, workspace.Rig, workspace.TargetPart, and workspace.LookPart are valid. Double-check the structure in the Roblox Studio Explorer to confirm these objects exist and are named correctly.
    2. MoveTo Function:

      • Make sure that Rig has a PrimaryPart set, as SetPrimaryPartCFrame requires it. If not, set the primary part of the model in the Properties panel or via a script.
    3. Player Movement Detection:

      • It seems you're trying to check if a player is moving before activating the moveToTarget function. There could be a timing problem if the player joins and the character hasn't loaded yet.
    4. Debugging Steps:

      • Print statements are helpful. Add print statements in your function to ensure that each part is being reached and that variables have the expected values.
      • For example, print when ProximityPrompt.Triggered is connected, and also verify when moveToTarget() and humanoid.MoveToFinished are triggered.
    5. Check Humanoid and PrimaryPart:

      • Ensure Rig has a Humanoid object. If Rig is a Model, ensure that the Humanoid exists and is functioning correctly.
      • Make sure Rig.PrimaryPart is correctly assigned. If it's not assigned correctly, attempts to manipulate its CFrame will fail.
    6. Ensure Proper Connections:

      • When using PlayerAdded and CharacterAdded, make sure your connections are executing by placing print statements to confirm that players and characters are correctly triggering these connections.
    7. Review ProximityPrompt Conditions:

      • Make sure the ProximityPrompt conditions are set correctly. Verify ActionText, ObjectText, and ensure the prompt is actually interactable during test runs.

    Here’s an enhanced version of the script with some debug prints to help locate where it might fail:

    local workspace = game:GetService("Workspace")
    local ProximityPrompt = workspace.DialoguePrompts.TestPrompt.ProximityPrompt
    local Rig = workspace.Rig
    local TargetPart = workspace.TargetPart
    local LookPart = workspace.LookPart
    
    local function moveToTarget()
        local humanoid = Rig:FindFirstChildOfClass("Humanoid")
        if humanoid then
            print("Moving to target position.")
            humanoid:MoveTo(TargetPart.Position)
            humanoid.MoveToFinished:Connect(function()
                print("Move to target finished.")
                local lookVector = (LookPart.Position - Rig.PrimaryPart.Position).unit
                Rig:SetPrimaryPartCFrame(CFrame.new(Rig.PrimaryPart.Position, Rig.PrimaryPart.Position + lookVector))
            end)
        else
            warn("Humanoid not found!")
        end
    end
    
    local playerMoving = false
    
    -- Event to check if player is moving
    game:GetService("Players").PlayerAdded:Connect(function(player)
        print("Player added:", player.Name)
        player.CharacterAdded:Connect(function(character)
            print("Character added:", character.Name)
            local human = character:WaitForChild("Humanoid")
            human.Running:Connect(function(speed)
                playerMoving = speed > 0
                print("Player moving:", playerMoving)
            end)
        end)
    end)
    
    ProximityPrompt.Triggered:Connect(function()
        print("Proximity prompt triggered.")
        if playerMoving then
            moveToTarget()
        else
            warn("Player is not moving.")
        end
    end)
    

    Run the script in Roblox Studio and watch the output for the printed messages. This should guide you to where the script is failing or if certain conditions are not met. Adjust the logical flow based on the behaviors observed during these print tests.