Trying to make a “tool look towards mouse” script work on server but I’m having problems
There’s no errors in the console and it prints “equip” just fine but the arm does not move
Note that it works fine when the server code is in the localscript so the problem is not in the arm move script itself
LocalScript:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local remote2 = game:GetService("ReplicatedStorage"):WaitForChild("Injector2")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local tool = script.Parent
local steppedConn
tool.Equipped:Connect(function()
steppedConn = RunService.Stepped:Connect(function()
remote2:FireServer(char, mouse.Hit.Position)
end)
end)
tool.Unequipped:Connect(function()
steppedConn:Disconnect()
end)
ServerScript:
local remote2 = game:GetService("ReplicatedStorage"):WaitForChild("Injector2")
local YAW_MIN = math.rad(-70)
local YAW_MAX = math.rad(70)
local PITCH_MIN = math.rad(-30)
local PITCH_MAX = math.rad(30)
remote2.OnServerEvent:Connect(function(plr, char, mousehit)
local rShoulder = char:WaitForChild("Torso"):WaitForChild("Right Shoulder")
local jointWorld = rShoulder.Part0.CFrame * rShoulder.C0
local dirLocal = jointWorld:PointToObjectSpace(mousehit)
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)
print("equip")
end)
I tested it and right off the bat I don’t understand why you would be modifying the arm itself wouldn’t you just modify the handle of the tool to look towards the mouse? Maybe I’m missing something this is not a arm position type of modification so why would you modify the arm position if you’re trying to move the tool itself
Yes but you aren’t being specific enough. Ivan probably doesn’t know you’re referring to using :FireAllClients(). He has to switch from using :FireServer() to learning how to use :FireAllClients()