Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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?

0
Do you just need a teleportation brick? User#3 0 — 9y
0
im not sure, im completely new to this function bubbaman73 143 — 9y
0
but im sure Vector3 should be fine bubbaman73 143 — 9y
0
What does the error say? Redbullusa 1580 — 9y
View all comments (6 more)
0
it just shows the red line below, but theres nothing in the output bubbaman73 143 — 9y
0
How about the Script Analysis pane? Redbullusa 1580 — 9y
0
oooh, nvm, i kept overlooking that GetPlayerFromCharacter is an event and needs () sorry for that bubbaman73 143 — 9y
0
strange, it still doesnt work bubbaman73 143 — 9y
0
Edit your question with the current script you have, please. Redbullusa 1580 — 9y
0
Yes, you need a server script to use Zyneak or my script. Redbullusa 1580 — 9y

2 answers

Log in to vote
0
Answered by
User#3 0
9 years ago

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.

0
this doesnt seem to work, it might be because p.Parent might mean workspace? im not sure bubbaman73 143 — 9y
Ad
Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

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
0
the if in this seems to error, but im not sure why it would bubbaman73 143 — 9y

Answer this question