✓ Accepted answer
you could also use region3 if you want them to be in a very specific point, ex. you dont want them to be able to access the shop from behind. they have to be within the region3 directly in front of your shop.
you can use FindPartsInRegion3 and check if part.Name == "HumanoidRootPart", and if true then you can press F to open the shop. I actually did this today and it worked very well :)
local inRegion = false
while wait(1) do
for _, Part in pairs(game.Workspace:FindPartsInRegion3(Region3.new(), nil, math.huge)) do
if Part.Name == "HumanoidRootPart" do
local player = Part.Parent
if player then
local humanoid = player.Humanoid
if humanoid then
inRegion = true
if inRegion then
wait(1)
inRegion = false
end
end
end
end
end
sorry if code looks bad did it on my phone
--> LINE 5 <-- the Region3.new() takes 2 arguments, 2 opposite vectors that create a rectangular prism.
if you have a part you can get the opposing 2 vectors like this:
Region3.new(brick.Position - (brick.Size/2), brick.Position + (brick.Size/2)
I hope I helped you, I tried my best :)
2 comments
Keydown is not reccomended. They say you should resort to using ContextActionService or UserInputService.
":connect" is deprecated. It's recommended to use ":Connect" but both work the same.