Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i check if a player is under a parts?

Im making a rain system and when someone goes indoors I want it to turn a particle off. Any ideas?

1 answer

✓ Accepted answer

You can use Raycasting which fires a ray above the player

local ray = Ray.new(player.Character.HumanoidRootPart,Vector3.new(0,100,0) -- creates a ray which goes 100 studs up from the HumanoidRootPart

local ignoreList = player.Character -- optional
local found = workspace:FindPartOnRay(ray,ignoreList or nil)

You can go on from there to check if found is a roof.

17 comments

0

How would i check if its touching a part though? (Any part)

0

You can use the found variable to check if it's a part or not

0

what does found return?

0

It returns a BasePart or nil

0

Okay, it also gives an error saying attempt to index nil with 'HumanoidRootPart' on line 1

0

BasePart/Terrain or nil*

0

Is player defined?

0

ye, i did game.Players.LocalPlayer.Character.HumanoidRootPart

0

Do a wait at that beginning of your script to let the character load in

0

Fixed it but now it says invalid argument #1 (Vector3 expected, got Instance)

0

Add another ) at the end of Vector3.new(0,100,0)

0

I already did that before

0

local ray = Ray.new(game.Players.LocalPlayer.Character.HumanoidRootPart,Vector3.new(0,100,0))

0

Oh, add .Position after HumanoidRootPart

0

Works, just keeps printing "Nil" even if i go under a part (i put it in a while loop)

0

Do you have an ignoreList

0

Nvm, i fixed it. I wasnt making another ray in the loop, bc if u move around u gotta make a new ray. Answer accepted

This discussion is preserved as it was. New answers, comments, and votes are closed.