I’ve never really grasped raycasting fully, but I tried to do this, and it doesn’t work for some reason. It’s super weird, cause if i look in a ceritan direction, i get the error “Players.Dogemeowbarf.PlayerGui.ScreenGui.LocalScript:27: attempt to index nil with ‘Instance’”
And if I look in another direction, It just gives me the baseplate, which is not what I want, cause i’m trying to raycast in the position of the players HumanoidRootPart. But yeah, please tell me what i’m doing wrong here.
local players = game:GetService("Players")
local uis = game:GetService("UserInputService")
local gui = script.Parent
local player = players.LocalPlayer
local character = player.Character
local hrp = character:FindFirstChild("HumanoidRootPart")
local torso = character:FindFirstChild("Torso")
local head = character:FindFirstChild("Head")
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
local function raycast()
local raycastResult = workspace:Raycast(hrp.Position, hrp.Rotation, params, 100000)
return raycastResult
end
local debounce = false
local debounceTime = 1
uis.InputBegan:Connect(function(inpObj, gpe)
if gpe then return end
if debounce == true then return end
if gui.Enabled == true then
if inpObj.KeyCode == Enum.KeyCode.R then
print(raycast().Instance)
end
end
end)