скрипт не работает,что делать local workspace = game:GetService("Workspace") local…
- 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)
- 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.
-
Initial Setup:
- Ensure that all path references like
workspace.DialoguePrompts.TestPrompt,workspace.Rig,workspace.TargetPart, andworkspace.LookPartare valid. Double-check the structure in the Roblox Studio Explorer to confirm these objects exist and are named correctly.
- Ensure that all path references like
-
MoveTo Function:
- Make sure that
Righas aPrimaryPartset, asSetPrimaryPartCFramerequires it. If not, set the primary part of the model in the Properties panel or via a script.
- Make sure that
-
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.
-
Debugging Steps:
- Print statements are helpful. Add
printstatements in your function to ensure that each part is being reached and that variables have the expected values. - For example, print when
ProximityPrompt.Triggeredis connected, and also verify whenmoveToTarget()andhumanoid.MoveToFinishedare triggered.
- Print statements are helpful. Add
-
Check Humanoid and PrimaryPart:
- Ensure
Righas aHumanoidobject. IfRigis a Model, ensure that theHumanoidexists and is functioning correctly. - Make sure
Rig.PrimaryPartis correctly assigned. If it's not assigned correctly, attempts to manipulate itsCFramewill fail.
- Ensure
-
Ensure Proper Connections:
- When using
PlayerAddedandCharacterAdded, make sure your connections are executing by placingprintstatements to confirm that players and characters are correctly triggering these connections.
- When using
-
Review ProximityPrompt Conditions:
- Make sure the
ProximityPromptconditions are set correctly. VerifyActionText,ObjectText, and ensure the prompt is actually interactable during test runs.
- Make sure the
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.
-