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

How to Sync Rotation on LocalPlayer with all other Players ?

Asked by 3 years ago
Edited 3 years ago

Hey ! Thanks for helping :D this community is amazing !

So, I'm synchronizing the Rotation of my Player Canon. Right now i'm using a RemoteEvent to update the rotation on the server, but Only the LocalPlayer and the Server see the Rotation. All the other players doesn't see it.

What is weird is that I tried to use that code to make a Part in workspace Rotate if the Player is Player1 and It work .. So I dont know why the Canon on the player isn't rotating on all other players

Do I need to do something special when I'm updating something that is on the player ??

Server Script that receive the data

Located in ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage.SyncPlayerCanon

RE.OnServerEvent:connect(function(player,angle)
    local char = player.Character
    local TankCanon = char:WaitForChild("Tank_Cannon_1")
    TankCanon.Rotation = Vector3.new(0, angle, 0)
end)

LocalScript on the player that Invoke the RemoteFunction

Located in StarterPlayerScripts

-- Setup initial Variables
local StarterPlayer = game:GetService("StarterPlayer")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local RemoteFunction = ReplicatedStorage.RemoteFunction
-- Wait to setup the LocalPlayer
repeat wait() until game.Players.LocalPlayer
local player = game.Players.LocalPlayer

local mouse = player:GetMouse()
local char = player.Character
local TankCanon = char:WaitForChild("Tank_Cannon_1")

local incr = 360/20

local RFSyncCanon = ReplicatedStorage.SyncPlayerCanon
local rs = game:GetService("RunService").RenderStepped
rs:Connect(function()
    local atan2 = 360 / (math.pi *2)
    local positionX = mouse.Hit.p.X - TankCanon.Position.X
    local positionZ = mouse.Hit.p.Z - TankCanon.Position.Z
    local angle = math.atan2(positionX, positionZ)* atan2
    TankCanon.Rotation = Vector3.new(0, angle, 0)
    RFSyncCanon:FireServer(angle) -- Fire Sync Rotation Event
end)
0
I found that I need to use the Motor6D currentAngle instead ThePoinball 20 — 3y

Answer this question