Problem with :MoveTo

I’m trying to make a player walk to the parts once they have touched a specific part. There’s actually no problem with the walking part itself. It works amazingly, but it literally tells all the players to walk to the parts. How could I prevent from other players walking there if I only want that one player who touched the part to walk there?

I’ve tried to do some research on the topic, but I cannot see anything mentioning that it will tell all the players in that server to walk to the parts.

Here’s the script:

game.Players.PlayerAdded:Connect(function(player)
	local Character = player.Character
	if not Character or not Character.Parent then
    Character = player.CharacterAdded:wait()
local humanoid = player.Character.Humanoid
local Detect = game.Workspace.MoveParts.Detect
-- Variables for the point(s) the zombie should move between
game.Workspace.DoorThingy.TouchEnded:Connect(function()
	humanoid.WalkSpeed = 10
local pointA = game.Workspace.MoveParts.A
	local pointB = game.Workspace.MoveParts.B
	local pointC = game.Workspace.MoveParts.C
 

humanoid:MoveTo(pointA.Position)
 
humanoid.MoveToFinished:Wait()
 

	humanoid:MoveTo(pointB.Position)
	
	humanoid.MoveToFinished:Wait()
 

	humanoid:MoveTo(pointC.Position)
	humanoid.WalkSpeed = 16
		end)
	end
	end)


1 Like

Hey, I can’t even understand what you’re trying to make! can you explain please?

1 Like

Once a player touches an invisible part, it will disable player movement and move the player to the line.
The invisible part is the part where the text is on.

The parts what are lightly transparent are basically what the player follows. But for some reason, it commands all the players to walk towards the parts if one the the current players in-game touches the part.

I understand from that that when the player touch the part, it move them and disable the walkspeed?

1 Like

Let me record a video on what it is supposed to do.

You do not have to use the PlayerAdded event. Your goal here would be to detect which player touched the part. This is achieved using the parameters at the end of the touch ended event.

This means your script should be:

game.Workspace.DoorThingy.TouchEnded:Connect(function(PlayerBodyPart) -- PlayerBodyPart gets the part touching the object
if PlayerBodyPart.Parent:FindFirstChild("Humanoid") ~= nil then -- Check if touching part is a player
    local humanoid = PlayerBodyPart.Parent:FindFirstChild("Humanoid") -- Find Player's humanoid
    humanoid:MoveTo(pointA.Position) -- Move ONLY the player touching the part
end
1 Like

Oh… Now I see. So I assume if the script detects anything touching the door, it’ll run the script.
Thank you so much! C:

A word of caution, you may want to use the touched event instead of the touchended event to detect touch, if you are trying to detect anything moving towards the door.

1 Like
local Door = script.Parent

Door.TouchEnded:Connect(function(PBP)
    if PBP.Parent:FindFirstChild("Humanoid")
        local chrctr = game.Players.LocalPlayer.Character

        chrctr:MoveTo(pointA.Position)
    end
end)
1 Like

Oh… :slight_smile:
I also tried to use the touched event but it didn’t work out for me at all. Since the script tries to run as fast as possible, it looped the touched event like 30 times. I also tried to tell it to only do it once by telling it:
“local blahblah = false
game.Workspace.DoorThingy.TouchEnded:Connect(function()
if blahblah == false then blahblah = true…”

but that refused to even run it.
And thank you, @Abd_Dev as well.

That is the main flaw with the touched event which is why many games do not use it. Some solutions to this problem include using a checker:

game.Workspace.DoorThingy.Touched:Connect(function(PlayerBodyPart) 
    if PlayerBodyPart.Parent:FindFirstChild("Humanoid") ~= nil and Checker == false then
        Debounce = true
        -- Do stuff
        wait(5)
        Debounce = false
    end

Alternative solutions include detecting magnitude, raycasting and region3 which are more accurate.

1 Like

Oh shoot… That becomes a bit too complex for my little brain and knowledge of coding. :slight_smile: But I’ll definitely look into it.

2 Likes

Oh god… I’ve ran into a new issue. I want to die.
I had two scripts, where one moved the player and the other one disabled the player’s controls. The one which disabled the controls is a local script and the other one is a server script. Is there any way to detect the player who touched the part, so I could refer to the player and disable their controls. Otherwise, it would disable everyone’s controls for a few seconds.

I know I’m anoying. You do not have to waste your time writing any kind of code again. Feel free to just refer to some roblox articles I could look into. :slight_smile:

Here’s the stupid script:

wait(0.1)
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
local Character = game.Players.LocalPlayer.Character
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local Detect = game.Workspace.MoveParts.Detect
-- Variables for the point(s) the zombie should move between
game.Workspace.DoorThingy.TouchEnded:Connect(function()
		game.Workspace.MoveParts.Blockade.CanCollide = false
	Controls:Disable()
end)

game.Workspace.MoveParts.B.TouchEnded:Connect(function()
	wait(1)
	game.Workspace.MoveParts.Blockade.CanCollide = true
	Controls:Enable()
	script.Parent.Frame.Position = UDim2.new(-0.05, 0,-1.05, 0)
					script.Parent.Frame:TweenPosition(UDim2.new(0.05,0,0.05,0), 'Out', 'Quad', 0.9, true)

				script.Parent.Frame:TweenPosition(UDim2.new(-0.05, 0,-1.05, 0), 'Out', 'Quad', 0.9, true)
				wait(1)
end)

I think it’s best to use “Touched” rather then “TouchEnded”. I might be wrong, but for me it’s more convenient to use. Anyways once they touch that part, a function is called. This function is “Touched”.

Also pass through an argument in the function brackets like this…

Part.Touched:Connect(function(hit) -- You can use something else if you want. 

Hit will mean that the function will pass an argument which is if the player has touched the part.

if hit.Parent:WaitForChild("Humanoid") then

We want to get hit’s parent and see if it’s a property of the player, in this case the humanoid. we’re using WaitForChild so that it will yield until it identifies the player’s humanoid if it’s dead.

Controls:Enable()

Enable the controls after.

1 Like

Hmm… Would that work for that specific player only who touched the part or would it enable/disable the controls globally?

Is this running through a local script. If then, yes it would only run for the local player. Also here is what the wiki says about TouchedEvents. Also for getting the player who touched the part, no ofc but you could’ve done a bit of research and found out on how to do it. There are plenty of resources, and not just limited to the forum.

1 Like

I completely understand that there are plenty of resources out here, but I cannot find the correct one which explains connecting to the player itself, not the humanoid.
And as I already though, we are not eliminating the fact that it still affects all of our users when even one person touches it. The hard part is to figure out how the script could figure out the exact local player who touched the part for me.

Or there could be a different way to do it. We could find out a way on how to disable player’s controls via server scripts. I have done some research on that and there are topics on how to do that out there, but they’re just so complicated.