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

please help with raycasting?

Asked by 9 years ago

How would Do something so that if the ray touches the player, they die?

1local ray = Ray.new(pos.CFrame.p, (endPos - pos.CFrame.p).unit * 300)      
2local hit, position = workspace:FindPartOnRay(ray, player.Character)
3local distance = (position - pos.CFrame.p).magnitude       
4ball.CFrame = CFrame.new(position, pos.CFrame .p) * CFrame.new(0, 0, 1.5) * CFrame.new(0, 0, -distance)    
5game.Debris:AddItem(ball, 1)       
6local sT = 0           
7local bv = Instance.new("BodyVelocity", ball); 
8bv.velocity = -ball.CFrame.lookVector * speed

1 answer

Log in to vote
0
Answered by 9 years ago

Hi, seimmaster07! In that script put this code in here -

1function onTouch(part)
2    local humanoid = part.Parent:FindFirstChild("Humanoid")
3    if (humanoid ~= nil) then   -- if a humanoid exists, then
4        humanoid.Health = 0 -- damage the humanoid
5    end
6end
7 
8script.Parent.Touched:connect(onTouch)

Thank you for asking! :D

Ad

Answer this question