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

This should bring the character to a certain position when the player clicks the GUI?

Code

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
 
Mouse.Button1Down:connect(function()
	Player:FindFirstChild("Torso").Position = -34.37, 0.5, 8.54
end)

4 comments

0

The torso is located in the players character, not in the player!

0

So i would have to re-write the script on line 5 to... I'm confused on how to add a players character.

0

NVM

0

Player.Character:MoveTo(-34.37, 0.5, 8.54) --You also may want to check if the character has loaded, and that the humanoid`s health is not 0

1 answer

When setting a position in the game, positions are defined as Vector3s. To set a new position or size or similar property, you need to explicitly state that you're generating a new Vector3 from a set of coordinates. You need to also move the Character of the Player, not the Player itself. Also, moving the player's torso only would get the player killed, as it only moves the singular part. If you want to move the entire model, I would suggest using CFrames, as it is made simple with the function :SetPrimaryPartCFrame. A CFrame can be made using a Vector3, so it's just one little extra step.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:connect(function()
    Player.Character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(-34.37, 0.5, 8.54)))
end)

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