for some reason, i cannot get .hit to work (even though ive used it many times before)
this is my localscript
local RemoteFunc = script.Parent.GetMouse
RemoteFunc.OnClientInvoke = function()
local Mouse = game.Players.LocalPlayer:GetMouse()
print(Mouse.Hit)
return Mouse.Hit
end
and it returns an insane value in the middle of the void any time i call on it over a part
serverscript
local function GetMouseHit(Character)
local Mouse = Tool.GetMouse:InvokeClient(game.Players:GetPlayerFromCharacter(Character)) :: CFrame
print(Mouse)
return Mouse.Position
end
local function mouseHit()
local mousePos = game.UserInputService:GetMouseLocation()
local ray = workspace.CurrentCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character or nil}
local result = workspace:Raycast(ray.Origin, ray.Direction * 1000, raycastParams)
if result then
return CFrame.new(result.Position), result.Instance, result.Distance -- so you dont need more functions (can be used like this: local hit, hover, dist = mouseHit(), or like this: local hit = mouseHit() or even like this: local _, hover, _ = mouseHit()
end
return nil -- wont return nil cuz of another return (unless theres no result)
end
This seems to be an attempt to avoid hackers.
Correct me if Iām wrong here, but this is a tool on the client, and both scripts are accessible.
So you may as well do it the normal way.
With a RemoteEvent;
LocalScript
local RemoteEvent = script.Parent:WaitForChild("MouseHit")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
script.Parent.Equipped:Connect(function()
mouse.Button1Down:Connect(function()
RemoteEvent:FireServer(mouse.Hit)
end)
end)
ServerScript
local RemoteEvent = script.Parent:WaitForChild("MouseHit")
RemoteEvent.OnServerEvent:Connect(function(plr, hit)
print(hit.Position)
end)