Hi everyone,
I want the player’s arm to follow their mouse, which I have written a script for. However, the movement is client-side, not server-side, like I’d prefer. I tried modifying the script to use a Remote Event to transfer information, but nothing happens on the server.
Local:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local event = game:GetService("ReplicatedStorage"):WaitForChild("UpdateArmWeld")
local YAW_MIN = math.rad(-70)
local YAW_MAX = math.rad(70)
local PITCH_MIN = math.rad(-30)
local PITCH_MAX = math.rad(30)
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local tool = script.Parent
wait(2)
local function rotateArm()
local hrp = char:WaitForChild("HumanoidRootPart")
local rShoulder = char:WaitForChild("Torso"):WaitForChild("Right Shoulder")
local jointWorld = rShoulder.Part0.CFrame * rShoulder.C0
local dirLocal = jointWorld:PointToObjectSpace(mouse.Hit.Position)
local yaw = math.atan2(-dirLocal.Z, dirLocal.X)
local pitch = math.asin(dirLocal.Unit.Y)
local yawClamped = math.clamp(yaw, YAW_MIN, YAW_MAX)
local pitchClamped = math.clamp(pitch, PITCH_MIN, PITCH_MAX)
rShoulder.Transform = CFrame.fromOrientation(0, yawClamped, pitchClamped + math.pi/2)
event:FireServer(rShoulder, yawClamped, pitchClamped)
print("Fired, info:", rShoulder.Name, yawClamped, pitchClamped)
end
local steppedConn
tool.Equipped:Connect(function()
steppedConn = RunService.Stepped:Connect(function()
rotateArm(char)
end)
end)
tool.Unequipped:Connect(function()
steppedConn:Disconnect()
end)
Server:
local updateArmWeldEvent = game:GetService("ReplicatedStorage").UpdateArmWeld
wait(2)
updateArmWeldEvent.OnServerEvent:Connect(function(player, rShoulder, yawClamped, pitchClamped)
rShoulder.Transform = CFrame.fromOrientation(0, yawClamped, pitchClamped + math.pi/2)
print("Received, info:", player.Name, rShoulder.Name, yawClamped, pitchClamped)
end)
The print debugs work, the info is fired and received, but the server does nothing with it. Can someone help?
Anything is appreciated!