Pop-up Shop GUI

Over the past few days, I’ve been trying to make a script that up make a screen GUI open when you stepped on a part or went into a specific area, I want to make an area where a shop GUI would open if you were to walk inside that said area,

(The part that would detect the player stepping on it would be non-collide with a transparency of 1, I don’t know if this would or wouldn’t affect anything)

but I wasn’t able to reach this goal with my current knowledge of scripting and a thorough search online. How would I be able to achieve this?

4 Likes

You can use OnTouched and fire a server that makes a playergui visible

3 Likes

LocalScript:

local player = game:GetService("Players").LocalPlayer;
local gui = script.Parent;

workspace.ShopPart.Touched:Connect(function(hit)
  if hit.Parent.Name == player.Name then
    gui.Visible = true;
  end;
end);
workspace.ShopPart.TouchedEnded:Connect(function(hit)
  if hit.Parent.Name == player.Name then
    gui.Visible = false;
  end;
end);

Roblox’s TouchEnded isn’t the best and I would probably find a better way to register when they stop touching it

2 Likes

You could use TweenSize() to get an nicer effect for the gui pop-up.

How did you not find it lol. There are so many tutorials. This one may help:

5 Likes

So in this case I think using a function called DistanceFromCharacter is best way of doing it.

It returns a number value

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local LocalPlayer = Players.LocalPlayer

local Shop = Workspace.Shop

local Distance = LocalPlayer:DistanceFromCharacter(Shop.Position)

print(Distance)

I gave you an example you have to do the rest if you have any questions feel free to ask me :smiley:

Edit:

Or use Region3

3 Likes

When I want to make a pop up Ui, I just use Magnitude. It is more reliable than Touched/TouchedEnded. There are videos out there that go into more depth about Magnitude.

The way I tacked this issue is by using the DistanceFromCharacter API. Bind this to a RunService:RenderStepped() loop and you can simply check the returned number as a distance. For example…

runService.RenderStepped:Connect(function()
    local distance = player:DistanceFromCharacter(Vector3.new(positionOfShopHitbox)

    if (distance < activationDistance) then
        --Show GUI
    else
        --Hide GUI
    end
end)

positionOfShopHitbox would be the Vector3 position of the invisible part that would traditionally be the .Touched object.

activationDistance is a number that would be the minimum distance between the object and the player
's primary part.

If you have any questions, let me know!

3 Likes

For some reason, I could barely find any videos about this, and the few that I did find were either outdated or wouldn’t work for some reason.

3 Likes

Are you sure, search again on YouTube the words pop up shop gui. There should be many tutorials.

I found a few, but as I said, they don’t work for me for some reason, I have the part as invisible and can-collide turned off if that affects anything.

1 Like

So I had figured out why my old script didn’t work, NOTE: I’m saying this so other people may learn from my mistakes and not make the same mistakes that I have made. Anyways, the reason why my script didn’t work was because my script made the frame from startergui visible, instead of playergui. Why this didn’t work was because startergui only refreshes when you respawn, and playergui refreshes in real time.

(If you really want a script to make a pop-up shop gui, then heres a script for those who don’t know how to make one)

script.Parent.Touched:Connect(function(hit) --function that runs when the script's parent (in this case the part) when it is touched
	if hit.Parent:FindFirstChild("Humanoid") then --checking if the thing that touched the part is a player
		game:GetService("Players"):FindFirstChild(hit.Parent.Name).PlayerGui.ScreenGui.Frame.Visible = true --makes the frame inside of the screengui visible
	end
end)

This is how your startergui should look
image

This is how your workspace should look
image

7 Likes