function createRay(input)
print(input) -- prints as a number like "0.014795400202274"
wait(10)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
local unitray = workspace.Camera:ViewportPointToRay(input.Position.X,input.Position.Y)
local ray = Ray.new(unitray.Origin, unitray.Direction * 500)
local hit = workspace:FindPartOnRayWithIgnoreList(ray,IgnoreList)
if hit then
game.ReplicatedStorage.print:FireServer(hit.Name)
end
end
end
function findHover(input,gameProcessedEvent)
print(input) -- prints as InputObject
if debounceMouse == false and input.UserInputType == Enum.UserInputType.MouseMovement and not gameProcessedEvent or debounceMouse == false and input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent then
print(input)
debounceMouse = true
createRay(input)
debounceMouse = false
end
end
Why does the first function print the number instead of the InputObject?
createRay() is also called from a BindToRenderStepped further down
When you call createRay from findHover, input is an InputObject, as you desire.
It’s your binding of createRay to render step using RunService:BindToRenderStep that’s the issue. The only argument passed to functions bound to render step when they are called is the delta time between the last render step and the current render step, which is a number. That number becomes input when the function is called.
ah, so to solve this, I’d basically have to define input as a defined variable outside of the function and just define it every time the InputChanged fires?
let’s have another example: if I were to have only one remote event, and have 2 different scripts firing the event, and have a server script to print the thing it fires. It wouldn’t print the same thing if the 2 scripts are different
local mousePositionX
local mousePositionY
function createRay()
print(mousePositionX.." "..mousePositionY)
if mousePositionX then
local unitray = workspace.Camera:ViewportPointToRay(mousePositionX,mousePositionY)
local ray = Ray.new(unitray.Origin, unitray.Direction * 500)
local hit = workspace:FindPartOnRayWithIgnoreList(ray,IgnoreList)
if hit then
game.ReplicatedStorage.print:FireServer(hit.Name)
end
end
end
function findHover(input,gameProcessedEvent)
print(input)
if debounceMouse == false and input.UserInputType == Enum.UserInputType.MouseMovement and not gameProcessedEvent or debounceMouse == false and input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent then
print(input)
debounceMouse = true
mousePositionX = input.Position.X
mousePositionY = input.Position.Y
createRay()
debounceMouse = false
end
end
Basically I just define the X and Y positions in their own variables, and I just call them in the renderstep function, since the mouse position doesnt update, if say, only the camera moves!