What do you want to achieve?
I’m using this code to detect when stones fired by a player’s skill are close enough to the ground, but often the stones simply cross the ground, or simply teleport to the final objective when they are far away.
Event = RSE.Stepped:Connect(function(ElapsedTime, DeltaTime)
if (Projectile.Position - RootPart.Position).Magnitude > SkillTable.Distance then
if BV then
BV:Destroy()
Direction = Vector3.new(0, -1, 0)
end
end
local Cast : RaycastResult = workspace:Raycast(OldPos, -(OldPos - Projectile.Position).Unit * 999, Params)
if Cast and Cast.Distance < 5 then
print(Cast.Distance)
if Event then Event:Disconnect() end
if BV then BV:Destroy() end
Projectile.Anchored = true
Projectile.Position = Cast.Position
local Detection = HitModule:HitBox(Character, {
["Type"] = "Magnitude",
["Range"] = SkillTable.Range,
["CFrame"] = CFrame.new(Cast.Position),
})
local ShakeDetection = HitModule:HitBox(nil, {
["Type"] = "Magnitude",
["Range"] = 50,
["CFrame"] = CFrame.new(Cast.Position),
})
if ShakeDetection then
for TCharacter, Distance in pairs(ShakeDetection) do
local TPlayer = PYS:GetPlayerFromCharacter(TCharacter)
if TPlayer == nil then continue end
Remotes.Effects:FireClient(TPlayer, "ShakeOnce", {
["Duration"] = 5,
["Preset"] = "Explosion"
})
end
end
Remotes.Effects:FireAllClients("GroundSmash", {
["Position"] = Cast.Position,
["Distance"] = 10,
["MaxRocks"] = 15,
["Size"] = Vector3.new(2, 2, 2),
["Cracked"] = true,
["Duration"] = 15
})
if Detection then
local Hitted = HitModule:HitApply(Character, Detection, SkillTable.HitTable)
if Hitted then
for TCharacter, Table in pairs(Hitted) do
local TRootPart = TCharacter:FindFirstChild("HumanoidRootPart")
if Table["Fling"] and TRootPart then
Table["Fling"].Part = TRootPart
Table["Fling"].Direction = {Vector3.new(math.random(0, 25) / 100, 1, math.random(0, 25) / 100)}
MainModule:Velocity(Table["Fling"])
end
end
end
end
task.delay(15, function()
local Tween = TSE:Create(Projectile, TweenInfo.new(1, Enum.EasingStyle.Linear), {["Size"] = Vector3.new(0.001, 0.001, 0.001)})
Tween:Play()
Tween.Completed:Wait()
Cache:ReturnPart(Projectile)
end)
end
OldPos = Projectile.Position
end)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking for some Raycast modules like FastCast and SecureCast, but they don’t work for the type of thing I’m trying to do, I’ve tried to take some examples and adapt them in my own way, but it never got to what I wanted.
Event = RSE.Stepped:Connect(function(ElapsedTime, DeltaTime)
if (Projectile.Position - RootPart.Position).Magnitude > SkillTable.Distance then
if BV then
BV:Destroy()
Direction = Vector3.new(0, -1, 0)
end
end
local Cast : RaycastResult = workspace:Raycast(OldPos, -(OldPos - Projectile.Position).Unit * 999, Params)
if Cast and Cast.Distance < 5 then
print(Cast.Distance)
if Event then Event:Disconnect() end
if BV then BV:Destroy() end
Projectile.Anchored = true
Projectile.Position = Cast.Position
local Detection = HitModule:HitBox(Character, {
["Type"] = "Magnitude",
["Range"] = SkillTable.Range,
["CFrame"] = CFrame.new(Cast.Position),
})
local ShakeDetection = HitModule:HitBox(nil, {
["Type"] = "Magnitude",
["Range"] = 50,
["CFrame"] = CFrame.new(Cast.Position),
})
if ShakeDetection then
for TCharacter, Distance in pairs(ShakeDetection) do
local TPlayer = PYS:GetPlayerFromCharacter(TCharacter)
if TPlayer == nil then continue end
Remotes.Effects:FireClient(TPlayer, "ShakeOnce", {
["Duration"] = 5,
["Preset"] = "Explosion"
})
end
end
Remotes.Effects:FireAllClients("GroundSmash", {
["Position"] = Cast.Position,
["Distance"] = 10,
["MaxRocks"] = 15,
["Size"] = Vector3.new(2, 2, 2),
["Cracked"] = true,
["Duration"] = 15
})
if Detection then
local Hitted = HitModule:HitApply(Character, Detection, SkillTable.HitTable)
if Hitted then
for TCharacter, Table in pairs(Hitted) do
local TRootPart = TCharacter:FindFirstChild("HumanoidRootPart")
Table["Fling"] and TRootPart then
Table["Fling"].Part = TRootPart
Table["Fling"].Direction = {Vector3.new(math.random(0, 25) / 100, 1, math.random(0, 25) / 100)}
MainModule:Velocity(Table["Fling"])
end
end
end
end
task.delay(15, function()
local Tween = TSE:Create(Projectile, TweenInfo.new(1, Enum.EasingStyle.Linear), {["Size"] = Vector3.new(0.001, 0.001, 0.001)})
Tween:Play()
Tween.Completed:Wait()
Cache:ReturnPart(Projectile)
end)
end
OldPos = Projectile.Position
end)
In case any of you have the same problem as me, what I did to fix it was basically this, I won’t give much information, just adapt it to your system.
You need Janitor and GoodSignal Modules.
How this work?
Do you need a Roblox speed modifier or do you make one of your own, changing the AssemblyLinearVelocity, the script will adapt to the speed, this contains some flaws, if I manage to fix them I probably won’t remember to update it from here so it will stay for yourself.
In my case I am using BodyVelocity along with this detection.