#How do i make 1 Gui work on multiple ProximityPrompts?

1 messages · Page 1 of 1 (latest)

karmic sierra
#

I want to make a system where you can buy a tool from a gui triggered by a prox, but i want to have 1 single gui that have dif tools to sell depending on the prox

hidden hinge
#

Then, when triggering the prompt, you can get the values you need stored from those instances

karmic sierra
#

Im pretty new to scripting how would i refrence those in scripts like it wouldnt know what the string value actually means

hidden hinge
#

Pretty simple, dont worry. You can simply reference them like any other instance.

Say for example this is your layout:

ProximityPrompt
Script
ToolName (StringValue)
ToolCost (NumberValue)

You input the values beforehand in the studio.

Im on the phone so i cant write code well, so heres a pseudocode of what you need to do:

Inside Script

local prompt = script.Parent
local toolName = prompt.ToolName.Value
local cost = prompt.ToolCost.Value

local yourGui = -- your gui

-- at this point, you now have everything you need to sell to the player, so you can go ahout this yourself. Maybe something like on prompt triggered, open your gui, insert toolName and cost, etc
karmic sierra
#

Alright and for the cost i can just say like something Player. leaderstats. Value = cost?

#

Wait i forgot the Cash

#

But yea

hidden hinge
#

Hm, you're actually gonna need to learn more about scripting to properly tackle this project, specifically:

  • the difference between server script and local scripts
  • remote events to let server communicate with the client and vice versa
  • (optional, but highly recommended) learn about ways to create a secure transaction system
#

These are the relevant topics to allow you to understand what youre doing when scripting this project

whole mapleBOT
#

studio** You are now Level 5! **studio

hidden hinge
# hidden hinge Pretty simple, dont worry. You can simply reference them like any other instance...

Oh, great. Sorry, you mentioned you were new to scripting. In that case, here's what you need to know..

Essentially, we want to let the client handle everything visually, like the GUI, and let the server handle the logic that truly matters, like the actual transaction. To do that, you can do something like this:

In addition to our serverscript here, you can use a RemoteEvent to tell the triggering player's client to open up the gui and populate the necessary labels. Of course, include the name and cost in the event's parameters.

On the client side, in your gui, setup your "confirm transaction" button to send a remoteEvent back to the server on click. Let the server check if the player can actually afford the item they're buying. If they dont, ignore and fail the transaction. If it does, then of course, deduct their balance and give them the item

#

What I wrote is pretty broad, but i feel it should be a good starting guide on how you could go about doing this

karmic sierra
#

Thanks ill try to whip up some trash script i made tomorow

#

Wish me luck

karmic sierra
#

@hidden hinge Hey dude

#

i made the gui open on all proximityprompts but i still havent figured out the tool purchasing

#

can you go more on detail abt that?

hidden hinge
# karmic sierra can you go more on detail abt that?

You can refer to the text I wrote above, I can't explain it better than that. Here's an analogy instead where the player, client, and server are people:

Player: triggers prompt

Server, to the client: Hey dude, your player triggered a prompt. This prompt is selling the "Item" that costs "Cost". Open up the GUI for him please.

Client: Sure. Hey player, here's your gui. GUI pops up

Player: Presses purchase button

Client, to server: Hey server, player wants to purchase the item. Let me know if they can afford it or not, please.

Server: Sure. Checks if player can afford.. They can, so I subtract their balance and give them the tool

Server, to client: They can afford it. I've deducted their balance and gave them the item.

Client: Great, thanks. Hey player, you got your item. Shows successful purchase gui or something

karmic sierra
#

yea but wbt yk getting the tool based on the prox

hidden hinge
#

I thought you've dealt with that already? You can parent the Tool itself to each prompt and use that to show to the player

karmic sierra
#

alright alright so i have only done it so the gui opens on every prox

#

now i just gotta make the button purchase dif tools based on what prox is being triggered

karmic sierra
hidden hinge
#

That's one way to do it, yes. Just use a script to get whatever value from it you want

karmic sierra
#

okay so... i put the tools in the proximityprompts

#

now i have a yes button in my gui

#

ima try to do the thing

#

on it

karmic sierra
hidden hinge
#

Yes, if you scripted it right

karmic sierra
#

do i need to insert a new server script?

#

for the tool buying?

hidden hinge
#

Yes, to feed the item and purchase details to the client

#

You have to script it yourself

karmic sierra
#

@hidden hinge yea im an idiot could you like tell me exactly what to do not make me copy and paste it but yk

#

more detailed

karmic sierra
#

i know im prob sounding so stupid rn but my whole game is dependent on this

#

and i gotta make this work

#

cause theres this bug in my game and this is what i need to fix it

hidden hinge
karmic sierra
#

i know about remote events, its when you want to do something with a local script and a server script

hidden hinge
#

When you send a RemoteEvent to the client, include all related details, like what item are they buying and how much, so you can put them in your gui like maybe "Do you want to buy item" or whatever

karmic sierra
#

remote event is kind of like a script

#

bridge

#

i meant

#

typo

hidden hinge
#

Then what exactly are you getting stuck at?

karmic sierra
#

i need more context

#

first off are we using string values?

#

and if so how does it know what the string value actually means

#

since its not the tool itself its just words

hidden hinge
#

The StringValue idea was off the top of my head. I figured you'd only need the name of the tool to display on the gui so just send the name when you fire the RemoteEvent. And to get the name, you can get it from a StringValue stored in the prompt.

karmic sierra
#

i dont need anything to display on the gui

#

its 1 gui

#

no text changes

#

i have a game about planets and you activate the proximityprompts to get a gui

#

and buy the planet

#

it says "are you sure you want to buy this item?"

#

i just want to make it so the button gives a dif tool depending on which the proximityprompt is parented to

hidden hinge
#

In that case, you still need to use the StringValue to let the client know which prompt they triggered. So that when they clicked purchase, you can just feed that value to your transaction

#

Whenever they trigger a prompt and you open the gui, also change the behavior of the purchase button, so that when it is clicked, it'll process the value you passed through.

karmic sierra
#

i should name the strings after the tools correct?

hidden hinge
#

Yes

karmic sierra
#

could you give an example script?

#

not to copy and paste ofc but i gotta get the visual

#

@hidden hinge if not its okay

hidden hinge
#

I cant atm. You can easily do this yourself, it's a simple system. Use what you know about RemoteEvents.

I can't say this any clearer. Use a RemoteEvent to pass the StringValue's value (tool name) to the client. In your client, create a function that handles receiving the event. In the function, open the gui, and store somewhere that the latest opened prompt is about the specific tool name. Use this value in your process when a player confirms their purchase.

hidden hinge
#

Don't worry if it's taking you a while to complete this system. You have to learn somehow. If you don't learn to script now, you'll just run into more problems in the future.

karmic sierra
#

do i have to do something to it

#

@hidden hinge

hidden hinge
#

The pseudocode I gave you lays out the logic of how the system should work. The next step is for you to translate it into actual code using your scripting knowledge. That’s where your technical skills come in.

karmic sierra
#

no but you said something about a remoteevnt to open a gui

#

but i already have that

#

so i can skip that?

karmic sierra
#

am i on the right path? @hidden hinge

#

@hidden hinge a little help here?

SERVER SCRIPT:
local Prox = script.Parent
local Tool = Prox.ClassicSword
local Cost = Prox.ToolCost
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("OpenToolBuy")
local Event2 = RS:WaitForChild("BuyTool")
Prox.Triggered:Connect(function(Player)
Event:FireClient(Player)
if Player.leaderstats.Cash.Value == Cost then
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value - Cost
Event2.OnClientEvent:Connect(function()
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
Prox.Parent:Destroy()
end)
end
end)

Client Script:
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("BuyTool")
local Button = script.Parent
local Player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
Event:FireClient(Player)
end)

karmic sierra
#

@hidden hinge you there?

karmic sierra
#

@hidden hinge

#

yo

karmic sierra
#

@hidden hinge good morning

hidden hinge
#

Dude I can't spoonfeed you the entire system. You gotta rely on your skills as a scripter to do this

If this was a video game, here's a loading screen hint for you:

Equip yourself with and understand the tools Lua gives you, such as functions, events, modules etc., and use those tools creatively to create the system.

hidden hinge
karmic sierra
#

If i fix that it will work?

hidden hinge
hidden hinge
whole mapleBOT
#

studio** You are now Level 6! **studio