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

Ontouch teleport to a brick?

Asked by
iNicklas 215 Moderation Voter
9 years ago

Instead of teleporting to a specific location, you just teleport to a brick named, for example, 11?

function onTouched(hit)
    - What to put in!
end

script.Parent.Touched:connect(onTouched)

If you could redirect me to a page that could explain this, i would be way happier than just getting the answer.

Help?

0
Add a code block so we can read it... just press the little lua button and put the script in betweem the two ~~~ lines. To change your question just press edit on the side, dont repost this! dragonkeeper467 453 — 9y

2 answers

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

This is what I assume you have so far.

TeleportPart = workspace["11"]

function onTouched(hit)

end

script.Parent.Touched:connect(onTouched)

What you want to do is find out if the part touching this teleporter is part of a player (and is ideally alive). Use:

:GetPlayerFromCharacter() - Returns a player instance from a character object, or nil if it doesn't exist.

:FindFirstChild() - Returns the child from a string, or nil if it doesn't exist.

TeleportPart = workspace["11"]

function onTouched(hit)
    local HumanoidIsFound = hit.Parent:FindFirstChild("Humanoid")
    local PlayerIsFound = game.Players:GetPlayerFromCharacter(hit.Parent)
    if hit.Parent and HumanoidIsFound and HumanoidIsFound.Health > 0 and PlayerIsFound then
        local Character = hit.Parent

    end
end

script.Parent.Touched:connect(onTouched)

Now teleport the character! Use either:

:MoveTo() - Moves the PrimaryPart of a model to the given Vector3 position.

:SetPrimaryPartCFrame() - Moves the PrimaryPart of a model to the given CFrame position.

TeleportPart = workspace["11"]

function onTouched(hit)
    local HumanoidIsFound = hit.Parent:FindFirstChild("Humanoid")
    local PlayerIsFound = game.Players:GetPlayerFromCharacter(hit.Parent)
    if hit.Parent and HumanoidIsFound and HumanoidIsFound.Health > 0 and PlayerIsFound then
        local Character = hit.Parent
        Character:MoveTo(TeleportPart.Position)
        --[[ Or
        Character:SetPrimaryPartCFrame(TeleportPart.CFrame)
        --]]
    end
end

script.Parent.Touched:connect(onTouched)

And then you're done!

0
Oh woah! Redbull, i love your explaining, i learn so much :D, i would upvote you, but I can't yet :/ iNicklas 215 — 9y
0
When it says "Health > 0, does it mean it only teleports if the player got more than 0 hp? iNicklas 215 — 9y
0
Correct. Essentially saying that it will only teleport those that are alive. It's totally optional. Redbullusa 1580 — 9y
Ad
Log in to vote
0
Answered by
funyun 958 Moderation Voter
9 years ago
a = script.Parent --What you step on
b = workspace.B --What you teleport to

a.Touched:connect( --When point A touched

function(part) --Do the following:
    local player = game.Players:GetPlayerFromCharacter(part.Parent) --The player that's controlling the character model that contains the part that touched A

    if player then --If player exists
        local torso = player.Character.Torso --The guy's torso
        torso.CFrame = b.CFrame * CFrame.new(0, 4, 0) --See note attached
    end
end 

)

So, we have the position of point B. We want to put the character's torso a little bit above the part so he doesn't get stuck in the ground. To do this, we first take the position of the exit node.

b.CFrame

Now, we have to get a point 4 studs above that. To do this, we use * to make a new position related to the position of the exit node.

b.CFrame * CFrame.new(0, 4, 0)

This takes the original CFrame of b, then makes a CFrame 4 units above that point. Got it?

Answer this question