Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I want to create a ray at my torso and get everything around me 5 studs away?

Asked by 10 years ago

Everything is tagged correctly, and i want it to also kill them if they are withing 5 studs of me I am only giving the chunk with the ray of my code.


ray = Ray.new(char.Torso.Position,Vector3.new(5,5,5)) coroutine.resume(coroutine.create(function() while wait() do if pent.Parent == game.Workspace then hit = Workspace:FindPartOnRay() print(hit.Name) if hit and hit.Parent:findFirstChild("Humanoid") then hit.Humanoid.Health = 0 end end end end))

1 answer

Log in to vote
0
Answered by
Nymint 85
10 years ago

To be honest, I don't have knowledge of Rays, but you can get the Radius by doing a simple formula.

-- LocalScript, Inside a player's playergui or backpack or character.

local radius = 10
local player = Game:GetService("Players").LocalPlayer
repeat wait() until player.Character
local t=player.Character:WaitForChild("Torso")

coroutine.resume(coroutine.create(function()
while wait(.05) do --Lag must be prevented, I suggest you to use wait() wisely.
for _,v in ipairs(Workspace:GetChildren() do
if v.ClassName=="Model" then -- Making sure it's a character model.
if Game.Players:GetPlayerFromCharacter(v) then -- Making sure it's a true player.
local t2=v:FindFirstChild("Torso") if t2 then
if (t.Position-t2.Position).Magnitude<=radius then --Formula
t2:BreakJoints()
end end end end end end end))
Ad

Answer this question