You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I am trying to make a wall dection by using ray casting
-
What is the issue? Basically it detects in air, after it goes through a wall
----//SERVICES
local PS = game:GetService("Players") -- Player Service
local RS = game:GetService("RunService")
local DS = game:GetService("Debris")
local TS = game:GetService("TweenService")
--//MAIN OBJECTS
local BONE = script.Parent
local BONE_TRAIL = BONE:WaitForChild("TRAIL")
--//FOLDERS
local NUM_VALUES_FOLDER = BONE:WaitForChild("NUM_VALUES")
--//VALUES
local SPEED = NUM_VALUES_FOLDER:WaitForChild("SPEED")
local DELAY = NUM_VALUES_FOLDER:WaitForChild("DELAY")
local DEBRIS_TIME = NUM_VALUES_FOLDER:WaitForChild("DEBRIS_TIME")
--//RAY_CAST_PARAMS
local PARAMS = RaycastParams.new()
PARAMS.FilterType = Enum.RaycastFilterType.Blacklist
PARAMS.FilterDescendantsInstances = {BONE}
PARAMS.IgnoreWater = true
--//MAIN FUNCTIONALITY
task.wait(DELAY.Value) -- Waiting if there is delay!
BONE_TRAIL.Enabled = true
BONE.Anchored = false
--//VELOCITY
local B_VELOCITY = Instance.new("BodyVelocity")
B_VELOCITY.Parent = BONE
B_VELOCITY.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
B_VELOCITY.Velocity = BONE.CFrame.LookVector * SPEED.Value
B_VELOCITY.Name = "VELOCITY"
local CONNECTION
CONNECTION = RS.Heartbeat:Connect(function(dt)
local RESULT = workspace:Raycast(BONE.Position, BONE.CFrame.LookVector*1.5, PARAMS)
--print("raycasting...")
if RESULT then
print("DONE!")
--B_VELOCITY:Destroy()
BONE.Anchored = true
for _, v in pairs(BONE:GetDescendants()) do
if v:IsA("ParticleEmitter") then
v:Emit(25)
end
end
DS:AddItem(BONE, DEBRIS_TIME.Value)
CONNECTION:Disconnect()
return
end
end)