Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

what would i use to make this MoveTo function work? (still unanswered, not working)

so im trying to use the MoveTo function to teleport the player who touched it. But im not sure where to go from here to make it activate when touched. Heres what i have so far.


game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(character)
p.Character:MoveTo(Vector3.new(214,20,119))
	
end)
end)





	

so would i use .Touched somewhere inside that? another function? or something else?

10 comments

0

Do you just need a teleportation brick?

0

im not sure, im completely new to this function

0

but im sure Vector3 should be fine

0

What does the error say?

0

it just shows the red line below, but theres nothing in the output

0

How about the Script Analysis pane?

0

oooh, nvm, i kept overlooking that GetPlayerFromCharacter is an event and needs () sorry for that

0

strange, it still doesnt work

0

Edit your question with the current script you have, please.

0

Yes, you need a server script to use Zyneak or my script.

2 answers

Your question is a bit unclear but I'll try to help you.

Workspace.yourBrick.Touched:connect(function(p)
	if(game.Players:GetPlayerFromCharacter(p.Parent) == nil) then return end -- This means that the part that touched this part isn't apart of a character.
       p.Parent:MoveTo(Vector3.new(214,20,119))
end)

Let's begin.

Touched Event

This fires when any brick touches the brick this event is attached to.

MoveTo Method

Quite simple. This moves the whole model to a point in the world based on the first parameter.

1 comment

0

this doesnt seem to work, it might be because p.Parent might mean workspace? im not sure

Scrap your script. There's no point in using the .PlayerAdded or the .CharacterAdded events. They're redundant.

What you should be focusing on is the .Touched event.

-- If this script is in the teleport part itself
TeleportBrick = script.Parent

function onTouched(hit) -- "hit" is the object that touched the teleport part
	-- Your code here
end

TeleportBrick.Touched:connect(onTouched)
-- This is a connection line. It establishes a "listener" to call the function.

You should add some safeguards to ensure that the model that's touching the teleport part is the character of the Player instance itself, such as the :GetPlayerFromCharacter() and the :FindFirstChild() methods.

  • :GetPlayerFromCharacter(): Verifies if the character is connected to a player. If true, it will return the player instance. If false, it will return nil.

  • :FindFirstChild(): Verifies if the object exists, utilizing the string of the name. If true, it will return the object. If false, it will return nil.

-- In your onTouched() function
local HumanoidIsFound = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
local PlayerIsFound = hit.Parent and game.Players:GetPlayerFromCharacter
if HumanoidIsFound and PlayerIsFound then -- If all of the prerequisites are good, then...
	hit.Parent:MoveTo(214, 20, 119) -- Teleport this character to here!
end

1 comment

0

the if in this seems to error, but im not sure why it would

This discussion is preserved as it was. New answers, comments, and votes are closed.