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

My script broke can someone help?

Asked by 9 years ago

So I am working on a teleport script and this is the best I can come up with

local player = game.Players.LocalPlayer  
local character = player.Character or player.CharacterAdded:wait()
function onTouched(hit)
    character.Head.Position = Vector3.new(80,2533.999,204.5)
    game.Players.LocalPlayer.Character["Left Arm"].Position = Vector3.new(-78.5,2532.499,204.5)
    game.Players.LocalPlayer.Character["Left Leg"].Position = Vector3.new(-79.5,2530.499,204.6)
    game.Players.LocalPlayer.Character["Right Arm"].Position = Vector3.new(-81,2532.499,204.5)
    game.Players.LocalPlayer.Character["Right Leg"].Position = Vector3.new(-80.5,2530.499,204.5)
    game.Players.LocalPlayer.Character["Torso"].Position = Vector3.new(-80,2532.499,204.5)

end

connection = script.Parent.Touched:connect(onTouched)

But sadly all it does is freeze my player -.- Somebody help :(

2 answers

Log in to vote
1
Answered by 9 years ago

A character has a thing called MoveTo. That's what we will be using. Some people use CFrame or other stuff like that but for this one we will use MoveTo. Oh, and another problem. To me, this is a serverscript, so how we will do this is not using LocalPlayer.

function teleport(hit)
    local h = hit.Parent:FindFirstChild('Humanoid') -- I am doing this so we can check if it is a char.
        if h == nil then return end
        hit.Parent:MoveTo(Vector3.new(-80, 2532.499, 204.5)) -- This is where MoveTo comes in.
end 

script.Parent.Touched:connect(teleport)

This also proves how you can turn long scripts into short scripts. I hope I helped!

Ad
Log in to vote
1
Answered by
FiredDusk 1466 Moderation Voter
9 years ago

There is an event called "MoveTo". Watch this tutorial from me to see how to use it. https://www.youtube.com/watch?v=sm8YL0jomFY

Answer this question