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

How do i teleport the player 10 studs up if the player touched a brick?

I tried to teleport the player 10 studs up when it touches it. This is what i came up with:

part = script.Parent
part.Touched:connect(function(hit)--Touched event!
    local humanoid=hit.Parent:FindFirstChild("Humanoid")--Finding the Humanoid!
    if humanoid ~=nil then--If the humanoid exists!
     local x = (hit).Parent.HumanoidRootPart.Position.X
     local y = (hit).Parent.HumanoidRootPart.Position.Y
     local z = (hit).Parent.HumanoidRootPart.Position.Z
     local y = y + 10
     print(x..","..y..","..z)
     humanoid:MoveTo(x..","..y..","..z)
    end
end)

It works, but the player only jiggles a little bit around and don't teleport 10 studs up. Can somebody help?

2 answers

✓ Accepted answer

Here are your problems from most to least important :

  • humanoid:MoveTo() function will make the humanoid WALK to the destination you put in the parameter, the reason why it jiggles instead of moving up, is because walking upward is simply illogical

  • you don't have to create a variable for every single axis, it is very inefficient, if you simply want to add value to a single axis then you could just use '+' operator between vector3 values

example :

hit.Parent.HumanoidRootPart.Position = hit.Parent.HumanoidRootPart.Position +Vector3.new(0,10,0)

-. Instead of asking 'if humanoid does not equals to nil' ask 'if humanoid exist' instead, simply giving an object as condition will return true if they exist

example:

if humanoid then
	--codes here
end

Here! Merry christmas!

script.Parent.Touched:Connect(function(P) -- On part touched connect function with the argument P
	local PL = game.Players:GetPlayerFromCharacter(P.Parent) -- Gets player
    local PT = PL.Character.Torso -- Gets the torso
    
    if PL then -- If the player has been found then
	if PT then -- If the player's torso has been found then
		PT.CFrame = PT.CFrame + Vector3.new(0,10,0) -- Teleports the player 10 studs up
	else -- If there isn't a torso then
		warn("Torso was not found") -- Warn that torso wasn't found in the console
	end
	else -- If the player wasn't found then
		warn("Player was not found") -- Warn that the player wasn't found in the console
	end
end)

5 comments

0

Thx! I will try it out.

1

I'd say it's not a good idea to just give scripts as answers. But you did say "Merry Christmas!" so I suppose it counts as a gift lol

0

Nah,

0

Its fine.

0

I think i changed my mind...

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