Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you make a gui show up based on how close a player is?

Asked by 6 years ago
Edited 6 years ago

So i want it so when a player walk up the the shop, when they get close enough to it, a shop gui pop up. There would be a debounce in this script so it doesn't run continuously. the debounce is set to true at first, the script would check if its true then make it false. once the player steps out of the range, the debounce would set to true so the player could return to the shop again, how would i do this? i know you would have to use "TouchEnded" but im not familiar with it :/

1 answer

Log in to vote
0
Answered by 6 years ago

You don't seem that familiar with scripting (you can tell me if I'm wrong). I'll try to keep it as easy as possible.

If you get more familiar with scripting (again, I might be wrong) I recommend using magnitude rather than touch events so you don't have to create an area that you have to touch. Here's a link just in case: http://wiki.roblox.com/index.php?title=Magnitude All magnitude is the distance between two points. Okay, now back on track...

In Roblox, there's three types of for loops: "while", "for", and "repeat". I will be using repeat in this example so you don't have to use bigger and more messy loops.

The way you use repeat is as follows:

repeat --[[ What you want to repeat ]] until --[[ Something that happens to stop it ]]

So when you walk to the shop, you want to open a GUI when you are close enough. What you want to do is create an area that you want to touch (a transparent, anchored, non-collideable block). When you touch that area you will open a shop GUI to purchase things.

I recommend using a LocalScript.

Example:

game.Workspace.shopBlock.Touched:connect(function() --When you touch the block
    game.StarterGui.Gui.GuiFrame.Visible = true --Makes your shop's GUI frame visible

    repeat wait() until game.Workspace.shopBlock.TouchEnded --Repeats wait() until the block is no longer touched

    game.StarterGui.Gui.GuiFrame.Visible = false --Makes your shop GUI frame no longer become visible
end)

If you have any problems or questions, please contact me. ;)

0
Thanks! i'm not the best at scripting, still learning so this really helped :D cruizer_snowman 117 — 6y
0
Great to hear that, I'm glad to help! lazycoolboy500 597 — 6y
Ad

Answer this question