local MaxDistanceToShop = 24
local id = script.Parent.ShopID.Value
wait ()
while true do
wait ()
local Player = game.Workspace["Main System"].Players:GetChildren()
for _,v in pairs (Player) do
if (script.Parent.Trader.Position - v.UpperTorso.Position).magnitude <= MaxDistanceToShop then
local Player = game.Players:FindFirstChild(v.Name)
if Player then
game.Workspace["Main System"].Events.OpenShopEvent:FireClient(Player,id)
end
end
end
end
With this script i can look Shop sided if the player is near enough to buy something but how whould you do this to look if a player is too far away to auto close the shop?
(The problem is there are more than 1 shop so i can't just do : magnitude <= MaxDistanceToShop because it would close the shop instant if it gets opened because you can't be near enough at all shops)

5 comments
Is the player touching the part if it opens up?
nope
it looks if the player is near enough (.magnitude)
Why not just put it in a local script to begin with instead of firing the client?
I dont follow the issue with this script. Why cant you just use the same thing for every shop and say if you go X far from X shop trader then close?