I need my game to be able to retrieve the Mouse.Hit position of each client every second or so. I have the following in a local script within the StarterPlayerScripts:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local MouseTargetEvent = ReplicatedStorage:WaitForChild("MouseTargetEvent") local mouse = game:GetService("Players").LocalPlayer:GetMouse() while wait(.1) do if mouse.Target ~= nil then curr_target = mouse.Target.Name end MouseTargetEvent:FireServer(mouse.Hit.p, curr_target) end
The global server event is located in ServerScriptService as:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local MouseTargetEvent = Instance.new("RemoteEvent", ReplicatedStorage) MouseTargetEvent.Name = "MouseTargetEvent" local function MouseTargetChangedFunction(player, mouse_pos, mouse_target) --print(player.Name, "has changed their mouse target") game.ReplicatedStorage.MousePosition.Value = mouse_pos --print(game.ReplicatedStorage.MousePosition.Value) if mouse_target ~= nil then -- handles cases where the mouse is on the sky (aka nothing) game.ReplicatedStorage.MouseTarget.Value = mouse_target --print(game.ReplicatedStorage.MouseTarget.Value) end end MouseTargetEvent.OnServerEvent:Connect(MouseTargetChangedFunction)
For whatever reason (probably that the MousePosition is global for some reason), the mouse locations of all players in the server are calculated rather than just that of the client. How can I fix this, while still being able to use the client's mouse position in a global script?