I’m trying to make a lightning drop move, where it drops the player to the ground if they are high up, but how would I check if they aren’t just jump height, and how would I teleport them down to the location? I think this has something to do with rays, but i’m not sure how to use it, but I use this function for rays.:
function ray(startpos, endpos, dis)
local Ignore = {game.Workspace.Players}
local test = Ray.new(startpos, CFrame.new(startpos, endpos).lookVector * dis)
local hit, pos, sf = game.Workspace:FindPartOnRayWithIgnoreList(test,Ignore)
return hit, pos, sf
end
To provide more context: If a player jumps, from that height they cannot activate the drop. If they are on a tall brick and jump from there (off the ground), it would activate. Let me know if anyone needs more context to what i’m trying to do…
Raycast with the origin being the rootpart position of the player and the direction being something like Vector3.new(0, -1000, 0). If the ray hits something, then teleport them to the ray hit position
local Origin = RootPart.Position
-- you should also add raycast params to ignore your character and whatever other parts you need to ignore
local Result = workspace:Raycast(Origin, Vector3.new(0, -1000, 0))
-- check if ray hit anything
if Result then
local Distance = (Origin - Result.Position).Magnitude
-- if distance between rootpart and ground below is more than 10
if Distance > 10 then
-- do lightning move
end
end
local Origin = RootPart.Position
function ray(startpos, endpos, dis)
local Ignore = {game.Workspace.Players}
local test = Ray.new(startpos, CFrame.new(startpos, endpos).lookVector * dis)
local hit, pos, sf = game.Workspace:FindPartOnRayWithIgnoreList(test,Ignore)
return hit, pos, sf
end
local h,p,sf = ray(Origin+ Vector3.new(0,8,0), char.HumanoidRootPart.CFrame * CFrame.new(0,-1000,0).p, 12)
if h then
local Distance = (Origin - h.Position).Magnitude
if Distance > 10 then
-- do stuff
You should use workspace:Raycast since FindPartOnRay is deprecated. Also you need to update the origin each time you use the lightning move (so probably put the “Origin” variable inside of the move function if you have one)
Assuming you defined “RootPart” as the HumanoidRootPart above in your script then yes. Also, if you wanted to teleport to where the ray hit then you can just set the RootPart’s CFrame to the hit position of the ray
If you insist on using workspace:FindPartOnRay then you should just use “p”. FindPartOnRay returns a tuple which has the hitPart and the hitPosition, and your 2nd variable “p” is the hitPosition
No, literally “p” is the hit position of the ray. You can try setting the rootpart’s position to “p” (btw you should probably add an offset so the character teleports a little bit higher than the hit position so players don’t get potentially stuck in the ground)
local ground = -- were
local root = -- were
local dist = root.Position.Y - ground.Position.Y
print(dist < 3 and 'the player is standing [or no?]' or 'the player is 100% not standing')
So nothing is erroring or printing, but nothing is happening even if i’m falling from a good height: Here’s my code
local MainModule = require(game.ServerScriptService.Modules.MainModule)
local cd = false
function ray(startpos, endpos, dis)
local Ignore = {game.Workspace.Players}
local test = Ray.new(startpos, CFrame.new(startpos, endpos).lookVector * dis)
local hit, pos, sf = game.Workspace:FindPartOnRayWithIgnoreList(test,Ignore)
return hit, pos, sf
end
local Origin = Root.Position
local h,p,sf = ray(Origin+ Vector3.new(0,8,0), Root.CFrame * CFrame.new(0,-1000,0).p, 12)
if h then
local Distance = (Origin - p).Magnitude
if Distance > 10 then
print("yahee")
Root.Position = p * Vector3.new(0,1,0)
local anim = char.Humanoid:LoadAnimation(script.Animation)
anim:Play()
local drop = script.Drop:Clone()
drop.Parent = Root
drop:Play()
wait(1)
anim:Stop()
wait(1.5)
drop:Destroy()
end
end