How can I check if a player’s HumanoidRootPart is less than 10 studs away than a certain part?
(assume I already have the HumanoidRootPart in a variable, and it’s a local script)
Any help is appreciated!
How can I check if a player’s HumanoidRootPart is less than 10 studs away than a certain part?
(assume I already have the HumanoidRootPart in a variable, and it’s a local script)
Any help is appreciated!
You should use magnitude of humanoid root part and the magnitude of the certain part. find the difference and check if its under your desired amount such as 30
How would I do that? I’ve never worked with magnitude.
DistanceFromCharacter
local Distance = player:DistanceFromCharacter(Object) -- whatever object
if Distance < 10 then -- if the Distance is less than 10
print"Player is nearby"
end
I could give a example such as
if (BasePart.Position - BasePart.Position).Magnitude <= 10 then
(i made a mistake but @DasKairo corrected me)
Its actually (BasePart.Position - BasePart.Position).Magnitude
oops, thanks for correcting me, i feel like your other post is more simple than magnitude
Yeah that worked perfectly, thank you!
You can use the Magnitude feature, as people above have stated. This can be done with a player character’s HumanoidRootPart to another part by doing this:
local part = game.Workspace:FindFirstChild("Part") -- "Part" is the name of the part you want to find the distance of
local plr = game.Players.LocalPlayer
local hroot = plr.Character:WaitForChild("HumanoidRootPart")
print((hroot.Position - part.Position).Magnitude) -- This should print the distance between the two parts
Roblox has a built in function known as DistanceFromCharacter
which is basically the same thing
print((hroot.Position - part.Position).Magnitude)
print(plr:DistanceFromCharacter(part.Position))
That too, my apologies. I hadn’t noticed it.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.