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

how can i make my teleport script work it only owrks in studio mode not in game?

wait(1) local spawn = script.Parent spawn.Touched:connect(function(hit)

game.Players.LocalPlayer.Character.Torso.CFrame=CFrame.new(Vector3.new(192.713, 7.374, -898.129))-- Teleport end)

thats the code, but it only works when im in studio mode. when i play the real game out oif studio mode it doesnt teleport me why??

3 comments

0

Use code blocks. I also recommend using auto correct when writing things to the public.

0

Also, when posting scripts, I recommend telling people if it is a module script, a server script, or a local script.

1

LocalPlayer can only be used from a local script. Use GetPlayerFromCharacter instead

1 answer

The problem is that you are trying to index LocalPlayer from a normal Script. You should use GetPlayerFromCharacter, and use hit.

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)

Also, please format your code next time. If this helped, please up vote and accept answer. If this didn't help, please explain in the comments.

1 comment

0

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

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