Hi guys I am trying to make a simulator shop where you will first be given a tool when you join so player can start using their tool. Should I make a BoolValue that is false and basicly if player has lets say x tool it will let you have tool. And let say you buy something in shop then the BoolValue will become true and it will detect if you still have the tool and delete it? Will it work? any other idea , I am willing to take
I use a data module stored in ServerScriptService to handle all Player attributes. That way, the client can’t change the data but can be sent a copy of it:
-- The is the Module script
local Data = {}
local PlayerData = {}
function Data.AddPlayer(Player, Data) -- adds a player to the PlayerData Table (Do this when a player joins)
PlayerData[Player] = Data
end
function Data.ReturnData(Player) -- Retrieves a player's data from the PlayerData Table
return PlayerData[Player]
end
function Data.RemovePlayer(Player) -- Removes a player from the PlayerData Table (Do this when a player leaves)
PlayerData[Player] = nil
end
return Data
Then in another script which monitors when a player joins & leaves, it has the actual data defined and adds it for the player:
local DataModule = require(game.ServerScriptService.DataModule)-- Require the Data module
local Data = {
-- whatever tools the players has in your instance:
flame = 1,
bombs = 1,
tool1 = true,
tool2 = false,
tool3 = true
}
-- This adds the Player and their Data to the main Data table
local function onPlayerJoin(player)
DataModule.AddPlayer(player, Data)
preparePlayer(player)
end
-- This removes the Player from the main Data table
DataModule.RemovePlayer(player)
In other server side scripts, I can then reference that main Data table and update info:
local DataModule = require(game.ServerScriptService.DataModule) -- Require the Data module
local playerData = DataModule.ReturnData(player)
playerData["flame"] = playerData["flame"] + 1
I can also update the client GUI to show it that data:
player.PlayerGui.ScreenGui.Pickups.bombNo.Text = playerData["bombs"]
1 Like