I am trying to get the mouse’s position. But it keeps breaking on me.
For some reason I always make an argument while firing the server and that argument just means nothing to the script but just the mouse. I tried hit, target, getting the X and Y position of the mouse, I will send both my scripts and the parenting of the tool. I have tried to make it as simplified as I can to get rid of any unnecessary things.
LocalScript (client):
local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local OnFired = tool:WaitForChild("OnFired")
local mousePos = mouse.Hit.Position
--activate gunshots
tool.Activated:Connect(function()
OnFired:FireServer(plr, mouse)
print(mousePos)
end)
ServerScript ( Server ) :
local tool = script.Parent
local ServerEvent = tool:WaitForChild("OnFired")
ServerEvent.OnServerEvent:Connect(function(plr, mouse)
local mousePos = mouse.Hit.Position
print(mousePos)
end)
When firing the server you don’t need to include a player object. The player object is automatically sent to the server as the first parameter. Also you can’t send the mouse itself to the server. You need to send the mouse hit position only.
tool.Activated:Connect(function()
OnFired:FireServer(plr, mouse.Hit.Position) -- Should be OnFired:FireServer(mouse)
print(mousePos)
end)
Well, I click once and it prints the position. So it works, but the problem is that every time I fire the event, it only prints the first position it was at. I click in every other direction and its still the position I clicked.
I suggested the same changes in a previous reply (I just didn’t provide the full code snippet in the hopes that you’d try to implement the changes yourself).