I've been trying to figure out how to detect a player's proximity to a block, for purposes of radiation in a Fallout-esque game I've been making. I cannot think of how I would get the script to detect if the player is within the, say, 10-stud area around the block so the player gathers Radiation (of which I have being kept track of with an IntValue inside the character).
✓ ANSWER ACCEPTED
How to detect the player's proximity to a specific block?
2 answers
✓ Accepted answer
Use Player:DistanceFromCharacter. It accepts a Vector3 position.
For example, if you want to get the distance between the player and a block:
local block = game.Workspace.RadiationPart
local distance = player:DistanceFromCharacter(block.Position)
Note that it returns 0 if the player's character does not exist.
Another way to do this is using .magnitude (which can be used for any object instead of just the player)
local block = game.Workspace.RadiationPart
local distance = (player.Character.Torso.Position - block.Position).magnitude
3 comments
0
Character is a model, so it doesn't have a Position property. You'll have to use the torso.
0
I keep forgetting that x.x
1
Or player.Character:GetModelCFrame().p
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I almost feel stupid for not thinking of this. Thanks!