Position and CFrame

I have a tool, there’s a local script and server script. The problem is the server script so ingnore the local one if you like.
local script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Event = tool.RemoteEvent

local function onActivated()
	local MouseHit = mouse.Hit.Position
	Event:FireServer(mouse.Hit.Position)
end

local function onUnequipped()
	--print("tool was unequipped")
end

local function onEquipped()
	--print("tool was equipped")
end

tool.Activated:Connect(onActivated)
tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped) 

server script:

local Players = game:GetService("Players")
local Event = tool.RemoteEvent
local char = nil
local charOrientation = nil

Event.OnServerEvent:Connect(function(player, position)
	--local ModelPart = game.ReplicatedStorage.Ground:Clone()
	--ModelPart.Anchored = true
	--ModelPart.CFrame = CFrame.new(position) * CFrame.new(0, 3.5, 0)
	--ModelPart.Parent = game.Workspace
	
	char = player.Character
	--charOrientation = char:FindFirstChild("HumanoidRootPart").CFrame
	--print(charOrientation)
	char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, position)
	
	for i = 0, 5 do
		if i == 0 then
			local part = game.ReplicatedStorage.Ground:Clone()
			part.Anchored = true
			part.CFrame = CFrame.new(position) * CFrame.new(0, 3.5, 0)
			part.Parent = game.Workspace
		else 
			local part = game.ReplicatedStorage.Ground:Clone()
			part.Anchored = true
			part.CFrame = CFrame.new(position) * CFrame.new(0, 3.5, 0) * CFrame.new(i*4, 0, 0)
			part.Parent = game.Workspace
		end
	end
end)

When i click, character faces the place i clicked and if i am in motion and click then i get teleported back a little. Is there a way to update the current position of player’s char?
I would appreciate any feedback!

Just set the rotation on the client and it would automatically replicate to the server.

1 Like

wow, that really helped! how did you know that? Usually to change something you have to do it on server and it would replicate to clients. How would you know that reverse of that would work just as fine and better?

The client is given network ownership over certain parts, including their own character. With network ownership, the client can change a part’s physical state however they want and it will replicate to the server.

1 Like

Because the character is a physics object. All physics object can have some network ownership that is the computer which controls it. As for the character, it is controlled by the client which as a result means that editing the character on the client replicates it automatically. This is the main reason why fly hacks and teleports exist.

1 Like