Help with Buyable zones

so, I am trying to Buyable zones
but there is a issue how can I know which zone they are trying to buy?
Screenshot_198
This is the module in replicated Storage

local module = {["ForestZone"] = {Name = "LavaZone",Price=300,ZoneLevel= 1},
["IceZone"] = {Name = "IceZone",Price=500,ZoneLevel= 1},
["LavaZone"] = {Name = "LightningZone",Price=800,ZoneLevel= 1},
["LightningZone"] = {Name = "LightningZone",Price=800,ZoneLevel= 1}

}


return module

and this are the server scripts parented to Zones to pop up a simple yes or no gui and to Check their money

local ProximityService = game:GetService("ProximityPromptService")

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")

local Module = require(game:GetService("ReplicatedStorage"):WaitForChild("Zone"))

local Zones = game:GetService("Workspace"):WaitForChild("Zones")

local zone = script.Parent

local TextLabel = zone:WaitForChild("SurfaceGui"):WaitForChild("TextLabel")

for i, v in pairs(Zones:GetChildren())do

print(v)

v:WaitForChild("SurfaceGui"):WaitForChild("TextLabel").Text = Module[v.Name]["Price"]

end

ProximityService.PromptTriggered:Connect(function(a,player)

Remotes.ZoneBuy:FireClient(player)

end)

Remotes.ZoneBuyCheck.OnServerInvoke = function(player,b,c)

print("YesButtonSignalTaken")

print(b)

print(c)

print(player.Values.Coins.Value)

end

And the local script to ınvoke server after Clicking yes button.

local ZoneRemote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("ZoneBuy")

local Gui = script.Parent.Parent.Parent

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")

local ZoneChecker = Remotes:WaitForChild("ZoneBuyCheck")

local Holder = script.Parent

local YesButton = Holder:WaitForChild("YesButton")

local NoButton = Holder:WaitForChild("NoButton")

ZoneRemote.OnClientEvent:Connect(function(a,b)

Gui.Enabled = true

end)

YesButton.Activated:Connect(function(a,b,c,d)

local Mentoriana = ZoneChecker:InvokeServer()

end)

NoButton.Activated:Connect(function()

Gui.Enabled = false

end)

so how can I know which Zone they are tyring to buy?

2 Likes

You can make the UI fully serversided and for the module script do

For the buttons use MouseButton1Down event

local module = {}

module.Zones = {
["ForestZone"] = {Name = "LavaZone",Price=300,ZoneLevel= 1},
["IceZone"] = {Name = "IceZone",Price=500,ZoneLevel= 1},
["LavaZone"] = {Name = "LightningZone",Price=800,ZoneLevel= 1},
["LightningZone"] = {Name = "LightningZone",Price=800,ZoneLevel= 1},
}

return module
1 Like
  • You have only one ServerScript in ServerScriptService (SSS)
  • That by a for loop checks all Zones in Zone folder
  • The Zones folder has Models/Folders with names as Zone1 etc.
  • Inside the Zone model there is at least 2 parts the SurfacePart that holds the SurfaceGui and the ProxPart that holds the ProximityPrompt, and anything else you want as the ZoneChecker or a Door, idk. The idea is that inside one model everything related to the Zones is included, then.
  • Within the loop in SSS script, it populate the text in SurfaceGuis, populate the text on prompts, and connect each ProximityPrompt to handle the proper data, obviously its in ServerSide.
  • The function for the ProximityPrompt will check the money, validates the buy, reduce player’s money, and fireClient to tell the sale sent fine or not, and the ProximityPrompt to disable (cause player already bought it, or idk depends on you)

So, you dont need the prompt to FireServer and then reply to Client.
Prompt is indeed in ServerSide with the ability to check the money and validate the sale by its own. And then just FireClient with the results

The ServerScript in SSS:

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
local Module = require(game:GetService("ReplicatedStorage"):WaitForChild("Zone")) -- Why on ReplicatedStorage?

local Zones = game:GetService("Workspace"):WaitForChild("Zones")

for i, v in ipairs(Zones:GetChildren())do
	-- Populate SurfaceGUI
	v.SurfacePart.SurfaceGui.NameLabel.Text = Module[v.Name]["Name"]	
	v.SurfacePart.SurfaceGui.PriceLabel.Text = "$"..Module[v.Name]["Price"]
	
	-- Populate ProximityPrompt
	v.ProxPart.ProximityPrompt.ObjectText = Module[v.Name]["Name"]
	v.ProxPart.ProximityPrompt.ActionText = "Buy it: ".."$"..Module[v.Name]["Price"]
	
	-- Here you should connect the proximity prompts of each zone
	v.ProxPart.ProximityPrompt.Triggered:Connect(function(player)
		local saleDone = false
		if player.Values.Coins.Value >= Module[v.Name]["Price"] then
			warn("Enough money to buy:", player.Values.Coins.Value)
			saleDone = true
			player.Values.Coins.Value -= Module[v.Name]["Price"]
			warn("Money after buy:", player.Values.Coins.Value)
		else
			warn("Not enough money:", player.Values.Coins.Value)
			saleDone = false
		end
		
		-- Fire the client telling if sale went fine or not?
		-- Send if sale went fine and send the proximity to disable on client side
		Remotes.ZoneBuy:FireClient(player, saleDone, v.ProxPart.ProximityPrompt)
	end)
end

The Module (Which should be in SSS, not in ReplicatedStorage)

local module = {
	["Zone1"] = {Name = "LavaZone", Price = 300, ZoneLevel = 1},
	["Zone2"] = {Name = "IceZone", Price = 500 ,ZoneLevel = 2},
	["Zone3"] = {Name = "LightningZone", Price = 800, ZoneLevel = 3},
	["Zone4"] = {Name = "ForestZone", Price = 900 , ZoneLevel = 4}
}
return module

The ClientScript in Player:

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")

Remotes:WaitForChild("ZoneBuy").OnClientEvent:Connect(function(saleDone, theProx)
	if saleDone then
		theProx.Enabled = false -- disable the prompt
	else
		warn("sorry not enough money")
	end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.