Hi.
I am in the process of making a cafe GUI, and I so far the player clicks on the item they want, but then I want the gui to wait until they are near the machine. Then the gui will say things like “Making drink…” and so on and will make the drink when they are near the machine.
The first is to check the players magnitude and see if they’re close to the machine.
The next way is to have a Collision box around the area you want the player to see the GUI. Then use region3 to check whether the player is inside the box or outside the box.
To expand on the magnitude thing, you could check the player’s HumanoidRootPart to the model’s magnitude in something like a while loop and if it is less than a certain value execute some code.
The absolute easiest way is to make an anchored, no-collide, fully transparent cube around the area in question. Then attach a Touch event to it and check if the part that touches it belongs to a player character model.
local Run = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Model = workspace.Model
local ModelRoot = Model.PrimaryPart
Run.Stepped:Connect(function(Delta)
local Distance = Player:GetDistanceFromCharacter(ModelRoot.Position)
if Distance <= 10 then --Studs.
print(Player.Name.." is within 10 studs of the model.")
--Do other actions here.
end
end)
I’m surprised no one has suggested “Player:GetDistanceFromCharacter” yet, it essentially handles all of the distance/magnitude calculations for you and returns a number value which represents the distance/magnitude in studs the player’s character is from a specified point in the world space.
Yeah, I was going to answer magnitude too, I think it’s because that’s what most devs are used to and it only works for characters. This looks a lot simpler for that though. I might try using this next time I need distance.