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

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

Asked by 6 years ago

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??

0
Use code blocks. I also recommend using auto correct when writing things to the public. hiimgoodpack 2009 — 6y
0
Also, when posting scripts, I recommend telling people if it is a module script, a server script, or a local script. hiimgoodpack 2009 — 6y
1
LocalPlayer can only be used from a local script. Use GetPlayerFromCharacter instead Perci1 4988 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The problem is that you are trying to index LocalPlayerfrom 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.

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 TheOwlFromSaturn 26 — 6y
Ad

Answer this question