Hello
I am having a problem replicating character movement in the server.
Client side is when the player turns their mouse to the left or right of the character then the character will turn to that as well.
Although the server really wants to replicate my client-side character even tho I have made a separate server script to do that.
Here is the video of that problem
Client-side:
local MouseFollower
MouseFollower = RunService.Heartbeat:Connect(function()
----- this is for make the character always stay in a specific Z value
if HumanoidRootPart.CFrame.Z~= workspace.Spawn.SpawnLocation.CFrame.Position.Z then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position.X, HumanoidRootPart.CFrame.Position.Y, workspace.Spawn.SpawnLocation.CFrame.Position.Z)
end
if Mouse.Hit.X+0.2>HumanoidRootPart.Position.X then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.fromOrientation(0, -math.pi/2, 0)
if not right then
RightEvent:FireServer()
end
right = true
elseif Mouse.Hit.X-0.2<HumanoidRootPart.Position.X then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.fromOrientation(0, math.pi/2, 0)
if right then
LeftEvent:FireServer()
end
right = false
end
end)
Tranfer server script
local LeftEvent = game.ReplicatedStorage.TurnLeft
local RightEvent = game.ReplicatedStorage.TurnRight
LeftEvent.OnServerEvent:Connect(function(player)
LeftEvent:FireAllClients(player)
end)
RightEvent.OnServerEvent:Connect(function(player)
RightEvent:FireAllClients(player)
end)
Client server script:
local LeftEvent = game.ReplicatedStorage.TurnLeft
local RightEvent = game.ReplicatedStorage.TurnRight
LeftEvent.OnClientEvent:Connect(function(player)
if player~=game:GetService("Players").LocalPlayer then
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
HumanoidRootPart.CFrame = HumanoidRootPart.CFrame:Lerp(CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.fromOrientation(0, math.pi/2, 0),1)
end
end)
RightEvent.OnClientEvent:Connect(function(player)
if player~=game:GetService("Players").LocalPlayer then
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
HumanoidRootPart.CFrame = HumanoidRootPart.CFrame:Lerp(CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.fromOrientation(0, -math.pi/2, 0),1)
end
end)