i have a modulescript with a function Placement.Raycasy, wich is used by 2 locl script. But the thing is that it only works when/before a mouse click, keep in mind my first local script fires the function when inout started `function InputStarted(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
SelectedInRaycast = Placement.Raycast() -- this thing!!!!!
Placement.Drag_Window(window)
elseif input.KeyCode == Enum.KeyCode.E then
SelectedUnits_InField = nil
end
end`
But when i try to fire the function in a renderStepped loop my raycast returns nil
connection = RunService.RenderStepped:Connect(function(dt)
local result = Placement.Raycast()
if result and result.Instance:IsDescendantOf(workspace.Match_Map.Robloxia.Tiles) then
print("clicked on tile :3")
end
if BuildingMode == false then
connection:Disconnect()
end
end)
i also tried an event based of mousebutton click in the same script wich worked.
Here is the function
function placement.Raycast()
cam = workspace.CurrentCamera
local mousePosition = UIS:GetMouseLocation()
local mouseRay = cam:ScreenPointToRay(mousePosition.X,mousePosition.Y)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {workspace.Match_Map.Robloxia.Map_Dimentions}
local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)
print(raycastResult)
return raycastResult
end
type or paste code here