Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Auto close a gui when a player is to far away from a Part?

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

0

Is the player touching the part if it opens up?

0

nope

0

it looks if the player is near enough (.magnitude)

0

Why not just put it in a local script to begin with instead of firing the client?

0

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?

1 answer

A common mistake, you don't know if you're position magnitude would be negative, consider using this:

I don't know if this will solve your problem, but it's the best thing that has a tiny hint of working, thanks.

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 math.abs((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

2 comments

0

This does not work to open the GUI has already worked, however, I have to check if the gui of exactly this script will be opened to then synonymous only from this script to close

0

Oh okay.

This discussion is preserved as it was. New answers, comments, and votes are closed.