This seems like a very easy question to answer, although I cannot find the answer. I have this big dictonary:(ignore the achievements and inventory section, since I’m gonna edit that later on).
local function SetDataTable()
local UserData = {
MainStats = {-- Coins, Gems, Level, XP, are listed in here
["Coins"] = 0,
["Gems"] = 0,
["Level"] = 1,
["XP"] = 0
},
--[[ Achievements = {--Stars in here
},
Inventory = {-- Trails and Titles
},]]--
CourseStats = {--Number of Coins and Gems collected in courses, Time, and Deaths
["LobbyCoins"] = 0,
["LobbyGems"] = 0
}
}
return UserData
end
Lobby Coins are how many coins you collected in the lobby.
Now with my coin handler I cannot increment the dictionary number. My question is how do you do that?
lobbycoins:Increment(1)
Here is the full script:(all you really need to pay attention to is the lobbyCoins:Increment
part. The rest works fine).
-- Coin handler
local DataStore2 = require(script.Parent.DataStore2);
game.Players.PlayerAdded:Connect(function(player)
local lobbycoins = DataStore2("LobbyCoins", player);
local coins = lobbycoins:Get();
if(coins == nil) then
coins = {};
lobbycoins:Set(coins);
end
game.ReplicatedStorage.RemoteEvents.coinManagerEvent:FireClient(player,coins);
end);
game.ReplicatedStorage.RemoteEvents.coinGatherEvent.OnServerEvent:Connect(function(player, coinID)
local coin;
local coins = game.Workspace.Coins:GetChildren();
for k,v in pairs(coins) do
if(v.CoinID.Value == coinID) then
coin = v;
break;
end
end
if(coin == nil) then
print("Not a valid coin!");
else
print(player:DistanceFromCharacter(coin.Position));
if(player:DistanceFromCharacter(coin.Position) < 35.0) then
local lobbycoins = DataStore2("LobbyCoins", player);
local temp = lobbycoins:Get()
table.insert(temp, coinID);
lobbycoins:Set(temp);
local coinStore = DataStore2("Coins", player);
local XPStore = DataStore2("XP",player);
if(coinStore:Get() == nil) then
coinStore:Set(0);
end
lobbycoins:Increment(1)
XPStore:Increment(1);
coinStore:Increment(coin.CoinValue.Value);
else
print("Player isn't near the coin!");
end
end
end)
This script was created by a friend of mine who was helping me at first, but can’t anymore due to real life issues. I get what the whole script does, I just can’t figure out why he put semicolons after each line of code. What does it do? Is it required?
Have a great day!