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

how can i fix this teleport taht wont work ?

Asked by 6 years ago

~~~~~~~~~~~~~~~~~script.Parent.Touched:connect(function(hit)

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

player.Character.Torso.CFrame = CFrame.new(Vector3.new(192.713, 7.374, -898.129))

end)

~~~~~~~~~~~~~~~~~

heres the error

11:26:38.627 - Stack End 11:26:38.629 - Torso is not a valid member of Model 11:26:38.630 - Stack Begin 11:26:38.632 - Script 'Workspace.Part.Script', Line 5 11:26:38.634 - Stack End 11:26:38.667 - Workspace.Part.Script:5: attempt to index local 'player' (a nil value) 11:26:38.671 - Stack Begin 11:26:38.674 - Script 'Workspace.Part.Script', Line 5 11:26:38.676 - Stack End

0
its really not that hard to read TheOwlFromSaturn 26 — 6y
0
also unless you're blind thats a code block TheOwlFromSaturn 26 — 6y
0
That's not a code block, look at my answer to see a code block. LordOfLuxury 84 — 6y
0
You're using code blocks incorrectly. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Sorry to say but almost every single line here is improper. I'll rewrite the script and do my best to explain what happened as best as I can.

script.Parent.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild('Humanoid')
    if humanoid then
        hit.Parent.HumanoidRootPart.CFrame = CFrame.new(192.713, 7.374, -898.129)
    end
end)

So the first thing I want to point out is the touched event. You'll want to have this if statement here to make sure the thing touching the part is a player and not another part.

local humanoid = hit.Parent:FindFirstChild('Humanoid')
if humanoid then
    -- Script stuff
end

Also, touched events detect the character, not the player. So instead of doing GetPlayerFromCharacter() (This line here is completely messed up anyways, it would take forever to explain) you can just access the character through the hit.Parent.

Lastly, the HumanoidRootPart is the PrimaryPart for the character. You'll always want to use CFrame and not Vector3 when teleporting the player.

I've tested this script and it works perfectly. Enjoy!

0
thankst TheOwlFromSaturn 26 — 6y
Ad

Answer this question