What do you want to achieve? Hello, I’m making a script that prints the player name in the console when they are in the zone, and when they are not prints that a player is not in the zone
What solutions have you tried so far? I have tried
local Workspace = game:GetService("Workspace")
local zone = script.Parent
while wait(.1) do
local partsInZone = Workspace:GetPartsInPart(zone)
for i,v in pairs(partsInZone) do
if v.Parent:FindFirstChild("Humanoid") then
print(v.Parent.Name, " Is in zone")
end
end
print("The zone is empty")
end
But this seems to print “The zone is empty” even when a player is in the zone
Current code:
local Workspace = game:GetService("Workspace")
local zone = script.Parent
while wait(.1) do
local partsInZone = Workspace:GetPartsInPart(zone)
for i,v in pairs(partsInZone) do
if v.Parent:FindFirstChild("Humanoid") then
print(v.Parent.Name, " Is in zone")
else
print("The zone is empty")
end
end
end
local zone = script.Parent
while wait(.1) do
local partsInZone = workspace:GetPartsInPart(zone)
if #partsInZone<1 then print("The zone is empty")
else
for i,v in pairs(partsInZone) do
if v.Parent:FindFirstChild("Humanoid") then print(v.Parent.Name, " Is in zone") end
end
end
end
local zone = script.Parent
while wait(.1) do
local partsInZone = workspace:GetPartsInPart(zone)
local humanoids=0
for i,v in pairs(partsInZone) do
if v.Parent:FindFirstChild("Humanoid") then
print(v.Parent.Name, " Is in zone")
humanoids+=1
end
end
if humanoids<1 then print("The zone is empty") end
end
To be honest it sounds to me like you could just use a ProximityPrompt to do this, When a player is close it will show the shop gui and when they leave the area the gui can be hidden.
Yeah but proximity prompts use BillBaordGuis, and I want to be using screen gui!
So I can display a gui when a player enters and hide it when they leave
Here’s a quick example for you:
Create a ProximityPrompt inside a part in workspace and name it “MyStorePrompt”, change it’s style to Custom in it’s properties
Create a GUI in PlayerGui for your store and add a localscript to it. Paste the following code into your LocalScript:
local MyStoreGui=script.Parent
local PPS=game:GetService("ProximityPromptService")
PPS.PromptShown:Connect(function(prompt) if prompt.Name=="MyStorePrompt" then MyStoreGui.Enabled=true end end)
PPS.PromptHidden:Connect(function(prompt) if prompt.Name=="MyStorePrompt" then MyStoreGui.Enabled=false end end)
local zone = script.Parent
while wait(.1) do
local partsInZone = workspace:GetPartsInPart(zone)
local playersInZone = {}
for index, v in pairs(partsInZone) do
if v.Parent:FindFirstChild("Humanoid") then
table.insert(playersInZone, v.Parent.Name)
end
end
if #playersInZone == 0 then
print("There's no player in the zone")
end
end