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

How to change player position with 'game.Players.LocalPlayer'?

im creating a game that if you click a textbutton on the screen, it will teleport the player to a certain Position. The code--

1 local player = game.Players.LocalPlayer 2 script.Parent.MouseButton1Click:Connect(function() 3 script.Parent.Parent.Visible = false 4 player.Position = game.Workspace.BattleMap.tp.Position 5 end)

line four is what i dont get. I need to reference the player and change its position. How must i do this?

It gives ma an error syaing 'Position' is nit a property of LocalPlayer

2 answers

Yes, you can change position. Your problem is that player isnt the object on workspace. To make it work, you need to fix directrion to part. Theres a script:

local player = game.Workspace
local tp = game.Workspace.BattleMap.tp

script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
player.Character.HumanoidRootPart.CFrame = CFrame.new(tp.Position.X,tp.Position.Y + 5,tp.Position.Z)

So character is a player parts, humanoid root part is a child of character and one of main part of player. Sp script teleports that part on tp part, +5 on Y position makes the character dont stuck

If you got error or something then comment me! If its worked than accept my answer pls!

1 comment

0

accepting answer button is under comments so accept and i can get points for helping you

player doesn't have a Position property. You can do player.Character.HumanoidRootPart.Position = game.Workspace.BattleMap.tp.Position But I suggest you use a RemoteEvent so a server-side script teleports the player and not a local one.

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