What do you want to achieve?
When the Proximity Prompt, the humanoid moves.
What is the issue?
Even when I trigger the prompt, the humanoid doesn’t move. The code inside the function works, it jsut doesnt work when paired with the proximity prompt.
What solutions have you tried so far?
Tried doing a while loop because I thought the problem was that the code only executes once so when I trigger the prompt, it doesn’t run because it was already executed.
local Character = script.Parent.Parent
local Humanoid = Character.Humanoid
local ProximityPromptService = game:GetService("ProximityPromptService")
script.Parent.Triggered:Connect(function()
for i,v in pairs(game.Workspace.Nodes:GetChildren()) do
Humanoid:MoveTo(v.Position)
Humanoid.MoveToFinished:Wait()
end
end)
It is not anchored. As I said the code for moving the humanoid works fine. It’s when I place it in the Proximity Prompt function that problems start occuring.
I managed to get it working by changing the script in the character to be a client script, and then to fire a remote event to the server to make the server do the work.
Here’s my code:
(In character, client)
local Character = script.Parent.Parent
script.Parent.Triggered:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer(Character)
end)
(In ServerScriptsService, server)
local re = game.ReplicatedStorage.RemoteEvent
re.OnServerEvent:Connect(function(plr, char)
local Humanoid = char.Humanoid
for i,v in pairs(game.Workspace.Nodes:GetChildren()) do
Humanoid:MoveTo(v.Position)
Humanoid.MoveToFinished:Wait()
end
end)
Let me know if the same works for you!
(Also, I advise changing the name of the remote event)
Your code is not something I would advise to use, it doesn’t change anything other than making the proximity prompt triggerable by hackers from any distance.
Hadn’t really thought about exploiting - thanks for the head up!
I thought RemoteEvents were made to cut off exploiters?
Edit: Nevermind, I understand it now
As I said if I just remove the proximity prompt like:
local Character = script.Parent.Parent
local Humanoid = Character.Humanoid
for i,v in pairs(game.Workspace.Nodes:GetChildren()) do
Humanoid:MoveTo(v.Position)
Humanoid.MoveToFinished:Wait()
end
Instead of:
local Character = script.Parent.Parent
local Humanoid = Character.Humanoid
local ProximityPromptService = game:GetService("ProximityPromptService")
script.Parent.Triggered:Connect(function()
for i,v in pairs(game.Workspace.Nodes:GetChildren()) do
Humanoid:MoveTo(v.Position)
Humanoid.MoveToFinished:Wait()
end
end)
THe NPC would walk to the nodes. So I really do feel like the proximity prompt has to do something with the problem.