So hello,
im making a sort dfa system thingy and doing that i wanted to use raycasting.
Well, it doesnt work like it has to do. Already tried hrp.CFrame.LookVector and -hrp.CFrame.LookVector with no success.
Snippet of code:
while holding == true do
local pos = hrp.Position
local result = workspace:Raycast(pos, -hrp.CFrame.UpVector * 42, params)
if result then
print("result")
end
task.wait()
end
I would assume updating the pos of the hrp would work but it still does nothing.
And yes im 100% sure holding is set to true.
params are = params.FilterDescendantsInstances = {char}
this is a local script btw, that should not matter right?
Do you may have a idea why my ray is not detecting anything?
while holding do
local pos = hrp.Position
local direction = -hrp.CFrame.UpVector * 42
local raycastResult = workspace:Raycast(pos, direction, params)
if raycastResult then
print("Hit something!")
local hitPart = raycastResult.Instance
-- Do something with the hitPart here
end
task.wait()
end
it doesnt work, the snippets of code before the while loop are:
local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local char = plr.Character
local hrp : Part = char:WaitForChild("HumanoidRootPart")
local myHum : Humanoid = char:WaitForChild("Humanoid")
local mytorso : Part = char:WaitForChild("Torso")
local countdownGui = require(game.ReplicatedStorage.Modules.CooldownGUI)
local floorMa = Enum.Material.Air
local CameraShaker = require(game.ReplicatedStorage.Modules.CameraShaker)
local camera = workspace.CurrentCamera
local range = 12
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
local deb = false
local remote = game.ReplicatedStorage.Remotes.Dfa
local holding = false
local canLand = false
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.Q then
if hrp.AssemblyLinearVelocity.Y <= -70 and myHum.FloorMaterial == floorMa then
print("holding")
holding = true
canLand = true
end
end
end)
myHum.FreeFalling:Connect(function(active)
if active then
if hrp.AssemblyLinearVelocity.Y <= -70 then
print("u cna dfa")
end
else
if canLand then
holding = false
print("landed")
canLand = false
end
end
end)
I don’t think that is how while loops work. At the start, since holding is false, the while loop just passes. Even if you set holding to true afterwards, the while loop won’t update. Try using RunService.RenderStepped instead, as far as I know its better anyway.