How do i get current players position

When making a hitbox system for my fighting game i noticed that the players position is a little delayed

so is there anyway to get the current position of the player or another way to avoid this issue?

1 Like

It could be an issue in your script. Can you please share your code?

ups i forgot to add my code

Server script:

local MoveFolder = script.Parent
local Player = MoveFolder.Parent
local Humanoid = Player:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

local Combo = 1
local MaxCombo = 5
local LastPunch = "Left"

local PunchCooldown = .4
local FinishCooldown = 3

local Damage = 2.4
local FinisherDamage = 4.8

local Anims = {
	["LeftPunch"] = Animator:LoadAnimation(script:WaitForChild("PunchLeft")),
	["RightPunch"] = Animator:LoadAnimation(script:WaitForChild("PunchRight")),
	["FinishPunch"] = Animator:LoadAnimation(script:WaitForChild("FinishPunch"))
}

local function Hitbox()
	local Part = Instance.new("Part", workspace)
	Part.Anchored = true
	Part.CanCollide = false
	Part.Position = Player.PrimaryPart.Position
end

script.Parent.RemoteEvent.OnServerEvent:Connect(function(PlayerInst)
	
	if Player:FindFirstChild("NoPunch") or Player:FindFirstChild("Stun") or Player:FindFirstChild("Blocking") then
		return
	end
	
	if Combo >= MaxCombo then
		
		Anims["FinishPunch"]:Play()
		Combo = 1
		
		game.ReplicatedStorage.Events.Cooldown:FireClient(PlayerInst, "Punch", FinishCooldown)
		
		local Tag = Instance.new("StringValue")
		Tag.Name = "NoPunch"
		Tag.Parent = Player
		game.Debris:AddItem(Tag, FinishCooldown)
		
		Hitbox()
		
	else
		
		if LastPunch == "Left" then
			LastPunch = "Right"
			Anims["RightPunch"]:Play()
		else
			LastPunch = "Left"
			Anims["LeftPunch"]:Play()
		end	
		
		Combo += 1
		
		game.ReplicatedStorage.Events.Cooldown:FireClient(PlayerInst, "Punch", PunchCooldown)
		
		local Tag = Instance.new("StringValue")
		Tag.Name = "NoPunch"
		Tag.Parent = Player
		game.Debris:AddItem(Tag, PunchCooldown)
		
		Hitbox()
		
	end
	
end)

local script:

local Keybind = Enum.UserInputType.MouseButton1

local InputSerive = game:GetService("UserInputService")

InputSerive.InputBegan:Connect(function(Key)
	if Key.UserInputType == Keybind then
		script.Parent.RemoteEvent:FireServer()
	end
end)

You don’t seem to have any major delays in the script, so that shouldn’t be too bad.
Regardless, can you please try moving Hitbox() to the start of the remote event function, to see if it helps?

No i does nothing, i think its something with the players position update

Gonna be getting a bit dodgy, but maybe doing this could help:

Part.Position = Player.PrimaryPart.Position + Player.PrimaryPart.Velocity * 0.3 --play with this number here a bit

It works 90% of the time, mostly breaks when you attack right before stopping then it moves foward but i found another solution, i just made the local script give the players position

The problem with my code is that it relies on the velocity at the time, and if the velocity changes within that small window then the brick goes in the wrong place.

i just made the local script give the players position

What exactly would that change though?

as i said the server side updates players position less often than the client side so i just made the client side give the position to the server side

ah. I guess that makes sense

char requirementtt

also before someone say that then the player could cheat giving a diferent position, i’ve already made the server side check if the player-given position is similar to the server position

This is a very old post so i dont really expect a response. But how did you make the server-side check?