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

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

Asked by 2 years ago

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

Log in to vote
1
Answered by 2 years ago

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!

0
accepting answer button is under comments so accept and i can get points for helping you SashaPro336 47 — 2y
Ad
Log in to vote
1
Answered by
Miniller 562 Moderation Voter
2 years ago

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.

Answer this question