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

How do I get position of my player using charecter?

Asked by 3 years ago
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local position
mouse.Move:connect(function(hit)
    position = mouse.hit.p
end)

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.Z then
        local TeleportLocation = CFrame.new(position)
        local Character = player.Character
        if (Character.Position - mouse.position).Magnitude > 100 then
            Character:SetPrimaryPartCFrame(TeleportLocation)
        else
            print ("Too far away")
        end
    end
end)

what im trying to do is basically get the position of smth using the mouse and teleport my player to the mouse. however an error shows that says 'Position is not a valid member of Workspace.Joseph_Joku please help!

1 answer

Log in to vote
0
Answered by
cegberry 432 Moderation Voter
3 years ago

The issue is that Character (A model) does not have a Position property. You will want to use their RootPart instead, which can be accessed with Character.PrimaryPart. Alternatively you could do Character.HumanoidRootPart or access their Head and any of their body parts. You can look up the parts by using the explorer

Ad

Answer this question