#How do i make 1 Gui work on multiple ProximityPrompts?
1 messages · Page 1 of 1 (latest)
One way I can think of off the top of my head is that each prompt has a StringValue and NumberValue children that store the Tool name and the cost, respectively
Then, when triggering the prompt, you can get the values you need stored from those instances
Im pretty new to scripting how would i refrence those in scripts like it wouldnt know what the string value actually means
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
Alright and for the cost i can just say like something Player. leaderstats. Value = cost?
Wait i forgot the Cash
But yea
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
I know abt all those
** You are now Level 5! **
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
@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?
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
yea but wbt yk getting the tool based on the prox
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
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
wait so just put the tool inside the proximityprompt?
That's one way to do it, yes. Just use a script to get whatever value from it you want
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
this gives a dif tool depending on which prox is being triggered right?
Yes, if you scripted it right
Yes, to feed the item and purchase details to the client
You have to script it yourself
@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
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
Touch up on your knowledge in RemoteEvents, you'll be using it frequently for this system. Refer to my analogy here on how youll let the server communicate with the client and vice versa. Use RemoteEvent to do so.
i know about remote events, its when you want to do something with a local script and a server script
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
Then what exactly are you getting stuck at?
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
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.
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
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.
i should name the strings after the tools correct?
Yes
could you give an example script?
not to copy and paste ofc but i gotta get the visual
@hidden hinge if not its okay
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.
Again, i feel this analogy explains it clearly. This can be your pseudocode
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.
well i do already have the gui opening system
do i have to do something to it
@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.
no but you said something about a remoteevnt to open a gui
but i already have that
so i can skip that?
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)
@hidden hinge you there?
@hidden hinge good morning
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.
You got the event functions all mixed up. server script is supposed to do :FireClient and localscript does .OnClientEvent or something, I forgot
If i fix that it will work?
Again, I know you said you know how events work, but touch up on your knowledge about them
Idk, you tell me
** You are now Level 6! **