You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Eliminate using a ton of remote events. -
What is the issue? Include screenshots / videos if possible!
If this scenario gets resolved, I should be able to figure out the rest…
Building an RPG game.
All stats are stored in server storage for protection from exploiters.
on a shop Gui, I have 3 buttons: Buy 1, Buy 10, Buy 100
Buy 1 button: buys a single item.
Buy 10 button: buys 10 of an item.
Buy 100 button: buys 100 of an item.
Currently I have a remote setup, an it does not work for obvious reasons in the code below. I have no clue how to use one remote for this setup. I need some inspiration or ideas AND HOW TO DO THIS THE RIGHT WAY
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Looked around, but could not find what I was looking for other than having a ton of remotes is bad.
I have stats such as player gold, level, exp, strength, stamina, agility, ability power, etc.
I have resources such as various mining ores, various wood types, etc.
SHOP HANDLER SERVER SCRIPT:
serverStorage = game:GetService("ServerStorage")
replicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
RemoteStats = replicatedStorage:WaitForChild("RemoteStats")
OreEvent = RemoteStats:FindFirstChild("OreEvent")
goldCoinsEvent = RemoteStats:FindFirstChild("GoldCoins")
local function buyStone(player,count)
if goldCoins.Value >= 100 then
stone.Value = stone.Value + count
goldCoins.Value = goldCoins.Value - 100
goldCoinsEvent:FireClient(player,goldCoins.Value)
OreEvent:FireClient(player, stone.Value)
end
end
local function buyTenStone(player, count)
if goldCoins.Value >= 1000 then
stone.Value = stone.Value + count
goldCoins.Value = goldCoins.Value - 1000
goldCoinsEvent:FireClient(player,goldCoins.Value)
OreEvent:FireClient(player, stone.Value)
end
end
Players.PlayerAdded:Connect(function(player)
Folder = serverStorage:WaitForChild(player.Name)
stone = Folder:FindFirstChild("Stone")
goldCoins = Folder:FindFirstChild("Gold")
wait(.1)
OreEvent:FireClient(player, stone.Value)
end)
OreEvent.OnServerEvent:Connect(buyStone)
OreEvent.OnServerEvent:Connect(buyTenStone)
BUY 1 BUTTON LOCAL SCRIPT:
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local shopGui = playerGui:WaitForChild("Shop1GUI")
local itemName = shopGui.InfoTab:WaitForChild("ItemName")
local stone = game.ReplicatedStorage.Items.Stone:Clone()
local replicatedStorage = game:GetService("ReplicatedStorage")
local RemoteStats = replicatedStorage:WaitForChild("RemoteStats")
local stoneEvent = RemoteStats:FindFirstChild("OreEvent")
local button = script.Parent
button.MouseButton1Click:Connect(function()
if itemName.Text == "Stone" then
local count = 1
stoneEvent:FireServer(count)
end
end)