You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to put the player’s position in a script (server script), because a portion of my script requires the player’s position (the portion in question handles the Damage Falloff mechanic of my shooter game)
What is the issue? Include screenshots / videos if possible!
It looks like game.Players in Scripts don’t have a Character in it, which is crucial for declaring the player’s position
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I already searched in the internet beforehand, but nothing appears that helps me
local Pos = P.Character.PrimaryPart.Position
local hrpP = Hit.Parent:FindFirstChildOfClass("HumanoidRootPart").Position or Hit.Parent.Parent:FindFirstChildOfClass("Humanoid").Position
Hi there! I think what your asking is “How do I change the position of a player in a server script?”
Well here’s the cool thing… You don’t need to!
Local scripts will translate a players position on the server AND client, and can be done by doing
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local postion = yourPosition.Position
wait(3)
hrp.Position = position
and just in case you still want to so it on a server script:
local players = game.Players
players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local position = yourPart.Position
wait(3)
hrp.Position = position
end)
These are just simple player teleport scripts, but this is just how you reference a player’s position. You can also do this by using remote events to get the local player position, but this is very exploitable, so these methods might be better, unless you are trying to get the player’s position at a certain time.
local players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
task.wait(10)
print(humanoidRootPart.Position) --humanoid root part's position after 10 seconds
end
player.CharacterAdded:Connect(onCharacterAdded)
end
players.PlayerAdded:Connect(onPlayerAdded)
For that you can just use .Magnitude on a position to get the distance of a player between a part something like (RootPosition - PartPosition).Magnitude and it’ll return the distance between the player and part.