anyone knows how to make a buy area system?
like with that
That’s when I get close, appears the menu to buy
in my simulator the name of the money is called “Coins”
if anyone knows, please help me, thanks
anyone knows how to make a buy area system?
like with that
in my simulator the name of the money is called “Coins”
if anyone knows, please help me, thanks
You have to check for the amount of coins the player who touches the part has.
Using whatever system you have for storing coins, you can then do:
local coinsNeeded = 1000
local notEnoughGui = player.PlayerGui[whatever it is]
if player.Coins >= coinsNeeded then
--code for what happens if they have enough
else
notEnoughGui.Visible = true
end
Before I state my reply, please note that the Scripting Help category isn’t a place to get free code; It is to aid those who are having issues with their code. Please consider this before you post a new topic.
To answer your question, you would use magnitude to check how close the player is to the barrier, and, if they’re close enough, open the UI. Then when you click the buy button, fire a remote that checks if the player has enough money, etc. then if they have enough make it so they own the area.
@CrimsonForce’s code works, however it trusts the client with everything allowing the player to bypass that wall just by setting their coins to a large amount on the client. Consider applying a similar concept to a server script.
Server:
local areaWalls = {
[workspace.Area1] = 500
}
for area, coinsNeeded in pairs (areaWalls) do
-- you could do a region3 or magnitude method of finding if the player is nearby, but that's up to you.
area.Touched:Connect(function()
-- get player from character
if player.leaderstats.Coins >= coinsNeeded then
-- move the player to next side or delete the wall on their client
else
NotEnoughCoins:FireClient(plr); -- customize this however you want
end
end)
end
I’m not sure if there are still exploits out there that still allow players to delete parts on their client that let them walk through walls so regardless of which kind of code you use, you should make sure everything after that wall confirms that player actually belongs there.
That’s why you set up “two-way authentication”. The client check is fine - you should have a check on the client as well, if your data is replicated, for immediate feedback. The server should also have a check for security purposes.
With this model, non-exploited clients can enjoy the fun of immediate responses to world interaction and exploited clients that attempt to access the remote have their requests rejected because of the server-side check. This can also catch clients that wrongly pass the condition and fire the remote, wherein the server takes charge and rejects the request due to not passing its checks.
There are, it’s as simple as calling destroy on something.