Hello everyone!
I am trying to make a system where a script will raycast from a player’s HumanoidRootPart to the ground, and if the part fills a certain criteria it will set values inside of the part accordingly, and then when stepping off the part or if it doesn’t match the part with the values it sets them to nil/false
My problem though is I cant seem to get my raycasts to actually cast rays.
local runService = game:GetService("RunService")
local rayDirection = Vector3.new(0,-5,0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local memory = nil
local plr = game.Players:GetPlayerFromCharacter(script.Parent)
local function handleCast(part,pos,material,norm)
print("I HIT SOMETHING!")
if part:FindFirstAncestorWhichIsA"Folder" then
part.Player.Value = plr
part.Occupied.Value = true
memory = part
end
if part ~= memory then
memory.Occupied.Value = false
memory.Player.Value = nil
end
end
runService.PreSimulation:Connect(function()
local rayOrigin = script.Parent.HumanoidRootPart.Position
local rayDirection = Vector3.new(script.Parent.HumanoidRootPart.Position.X,script.Parent.HumanoidRootPart.Position.Y-5,script.Parent.HumanoidRootPart.Position.Z)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
handleCast()
end
end)
Here is my script, I have no clue why its doing this. Any help is appreciated!