Oh yeah, and here’s an example from one of my other games. All of the code in this game works just fine! It’s so confusing why it refuses to work in my new game, but I’m probably just being a doofus
Anyways:
Module
local Players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local lighting = game:GetService("Lighting")
local tweenService = game:GetService("TweenService")
local dataStoreService = game:GetService("DataStoreService")
local marketPlaceService = game:GetService("MarketplaceService")
local badgeService = game:GetService("BadgeService")
local dataStore = dataStoreService:GetDataStore("DataStore")
local mainGame = replicatedStorage:WaitForChild("MainGame")
local remotes = mainGame:WaitForChild("Remotes")
local vipGamePass = 42960558
local extraSpeedGamePass = 43113220
local metDeveloperBadge = 2127847888
local playBadge = 2127861595
local gameDevTag = {}
local adminTag = {56437368, 411648684, 3231488167, 1637468247, 681235830, 117648590, 1226217219}
local soundDesignerTag = {}
local diamondTag = {3231488167}
local crucible = {56437368}
local plrStats = {}
function plrStats.LoadChatTags(player)
local tags = Instance.new("Folder",player)
tags.Name = "Tags"
if player.UserId == 56437368 then
local newTag = Instance.new("IntValue",tags)
newTag.Name = "🛠"
local chatColor = Instance.new("Color3Value",newTag)
chatColor.Name = "ChatColor"
chatColor.Value = Color3.fromRGB(85, 255, 0)
local tagColor = Instance.new("Color3Value",newTag)
tagColor.Name = "TagColor"
tagColor.Value = Color3.fromRGB(253, 41, 67)
elseif table.find(diamondTag, player.UserId) then
local newTag = Instance.new("IntValue",tags)
newTag.Name = "💎"
local chatColor = Instance.new("Color3Value",newTag)
chatColor.Name = "ChatColor"
chatColor.Value = BrickColor.new("Pink").Color
local tagColor = Instance.new("Color3Value",newTag)
tagColor.Name = "TagColor"
tagColor.Value = Color3.fromRGB(255, 102, 204)
elseif table.find(gameDevTag, player.UserId) then
local newTag = Instance.new("IntValue",tags)
newTag.Name = "⚙️"
local chatColor = Instance.new("Color3Value",newTag)
chatColor.Name = "ChatColor"
chatColor.Value = BrickColor.new("Electric blue").Color
local tagColor = Instance.new("Color3Value",newTag)
tagColor.Name = "TagColor"
tagColor.Value = Color3.fromRGB(9, 137, 207)
elseif table.find(adminTag, player.UserId) then
local newTag = Instance.new("IntValue",tags)
newTag.Name = "🛡️"
local chatColor = Instance.new("Color3Value",newTag)
chatColor.Name = "ChatColor"
chatColor.Value = BrickColor.new("Really red").Color
local tagColor = Instance.new("Color3Value",newTag)
tagColor.Name = "TagColor"
tagColor.Value = Color3.fromRGB(255, 0, 0)
elseif table.find(soundDesignerTag, player.UserId) then
local newTag = Instance.new("IntValue",tags)
newTag.Name = "💿"
local chatColor = Instance.new("Color3Value",newTag)
chatColor.Name = "ChatColor"
chatColor.Value = BrickColor.new("Bright violet").Color
local tagColor = Instance.new("Color3Value",newTag)
tagColor.Name = "TagColor"
tagColor.Value = Color3.fromRGB(107, 50, 124)
elseif marketPlaceService:UserOwnsGamePassAsync(player.UserId, vipGamePass) then
local newTag = Instance.new("IntValue",tags)
newTag.Name = "👑"
local chatColor = Instance.new("Color3Value",newTag)
chatColor.Name = "ChatColor"
chatColor.Value = BrickColor.new("Deep orange").Color
local tagColor = Instance.new("Color3Value",newTag)
tagColor.Name = "TagColor"
tagColor.Value = Color3.fromRGB(255, 176, 0)
end
end
function plrStats.LoadData(player)
local playerData = replicatedStorage.MainGame.GameStorage.Templates.PlayerDataFolder:Clone()
playerData.Name = player.Name
playerData.Parent = replicatedStorage.MainGame.GameStorage.PlayerData
local serverPlayerData = serverStorage.MainGame.Templates.PlayerDataFolder:Clone()
serverPlayerData.Name = player.Name
serverPlayerData.Parent = serverStorage.MainGame.PlayerData
local inMenu = Instance.new("BoolValue")
inMenu.Name = "InMenu"
inMenu.Value = false
inMenu.Parent = player
local isBanned = Instance.new("BoolValue")
isBanned.Name = "IsBanned"
isBanned.Value = false
isBanned.Parent = player
local banReason = Instance.new("StringValue")
banReason.Name = "Reason"
banReason.Value = ""
banReason.Parent = isBanned
local timesKicked = Instance.new("IntValue")
timesKicked.Name = "TimesKicked"
timesKicked.Value = 0
timesKicked.Parent = player
local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = serverPlayerData
local equipped = Instance.new("StringValue")
equipped.Name = "Equipped"
equipped.Parent = serverPlayerData
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 0
level.Parent = leaderstats
local exp = Instance.new("IntValue")
exp.Name = "CurrentExp"
exp.Value = 0
exp.Parent = level
local maxExp = Instance.new("IntValue")
maxExp.Name = "MaxExp"
maxExp.Value = 150
maxExp.Parent = level
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
local gems = Instance.new("IntValue")
gems.Name = "Gems"
gems.Value = 0
gems.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
local rewardsClaimed = Instance.new("Folder")
rewardsClaimed.Name = "RewardsClaimed"
rewardsClaimed.Parent = player
local cashData, levelData, currentExpData, maxExpData, gemsData, winsData
local bannedData, reasonData
local weaponsData
local equippedData
local rewardsData
local success,errorMessage = pcall(function()
cashData = dataStore:GetAsync("cash-"..player.UserId)
gemsData = dataStore:GetAsync("gems-"..player.UserId)
levelData = dataStore:GetAsync("level-"..player.UserId)
currentExpData = dataStore:GetAsync("currentExp-"..player.UserId)
maxExpData = dataStore:GetAsync("maxExp-"..player.UserId)
winsData = dataStore:GetAsync("wins-"..player.UserId)
weaponsData = dataStore:GetAsync("weapons-"..player.UserId)
equippedData = dataStore:GetAsync("equipped-"..player.UserId)
rewardsData = dataStore:GetAsync("rewards-"..player.UserId)
bannedData = dataStore:GetAsync("banned-"..player.UserId)
reasonData = dataStore:GetAsync("banReason-"..player.UserId)
end)
if success then
cash.Value = cashData or cash.Value
gems.Value = gemsData or gems.Value
wins.Value = winsData or wins.Value
level.Value = levelData or level.Value
exp.Value = currentExpData or exp.Value
maxExp.Value = maxExpData or maxExp.Value
isBanned.Value = bannedData or isBanned.Value
banReason.Value = reasonData or banReason.Value
if weaponsData then
for _, weapon in pairs(weaponsData) do
if serverStorage:WaitForChild("MainGame"):WaitForChild("Tools"):WaitForChild("ShopTools"):FindFirstChild(weapon) then
local weaponClone = serverStorage:WaitForChild("MainGame"):WaitForChild("Tools"):WaitForChild("ShopTools"):FindFirstChild(weapon):Clone()
weaponClone.Parent = inventory
end
end
else
warn("No weapons data for "..player.Name)
end
if equippedData then
equipped.Value = equippedData or equipped.Value
player:WaitForChild("PlayerGui")
remotes:WaitForChild("SendEquipped"):FireClient(player, equippedData)
end
if rewardsData then
for _, reward in pairs(rewardsData) do
local rewardTag = Instance.new("StringValue")
rewardTag.Name = reward
rewardTag.Parent = rewardsClaimed
end
else
warn(player.Name.." has not collected any rewards!")
end
else
warn("No Data for "..player.Name.."!")
end
if marketPlaceService:UserOwnsGamePassAsync(player.UserId, vipGamePass) then
local character = player.Character or player.CharacterAdded:Wait()
player.Character:WaitForChild("Humanoid").MaxHealth = (100 * 0.2 + 100)
player.Character:WaitForChild("Humanoid").Health = (100 * 0.2 + 100)
end
if isBanned.Value == true and player.UserId ~= 56437368 then
player:Kick(banReason.Value)
end
coroutine.wrap(function()
while player do
task.wait(300)
if marketPlaceService:UserOwnsGamePassAsync(player.UserId, vipGamePass) then
player.leaderstats.Cash.Value += 1500
end
end
end)()
if Players:FindFirstChild("RoboBoy013") then
local Plrs = game.Players:GetPlayers()
for i = 1, #Plrs do
local plr = Plrs[i]
if not badgeService:UserHasBadgeAsync(plr.UserId, metDeveloperBadge) then
badgeService:AwardBadge(plr.UserId, metDeveloperBadge)
local success, result = pcall(function()
return badgeService:GetBadgeInfoAsync(metDeveloperBadge)
end)
remotes:WaitForChild("PlayerGotBadge"):FireAllClients(player, result.Name)
end
end
end
if not badgeService:UserHasBadgeAsync(player.UserId, playBadge) then
local success, result = pcall(function()
return badgeService:GetBadgeInfoAsync(playBadge)
end)
remotes:WaitForChild("PlayerGotBadge"):FireAllClients(player, result.Name)
badgeService:AwardBadge(player.UserId, playBadge)
end
end
function plrStats.SaveData(player)
local success, errorMessage = pcall(function()
dataStore:SetAsync("cash-"..player.UserId, player.leaderstats.Cash.Value)
dataStore:SetAsync("gems-"..player.UserId, player.Gems.Value)
dataStore:SetAsync("level-"..player.UserId, player.leaderstats.Level.Value)
dataStore:SetAsync("currentExp-"..player.UserId, player.leaderstats.Level.CurrentExp.Value)
dataStore:SetAsync("maxExp-"..player.UserId, player.leaderstats.Level.MaxExp.Value)
dataStore:SetAsync("wins-"..player.UserId, player.leaderstats.Wins.Value)
dataStore:SetAsync("banned-"..player.UserId, player.IsBanned.Value)
dataStore:SetAsync("banReason-"..player.UserId, player.IsBanned.Reason.Value)
local weapons = serverStorage:WaitForChild("MainGame"):WaitForChild("PlayerData"):FindFirstChild(player.Name).Inventory:GetChildren()
local weaponsTable = {}
for _, v in pairs(weapons) do
table.insert(weaponsTable, v.Name)
end
dataStore:SetAsync("weapons-"..player.UserId, weaponsTable)
if serverStorage:WaitForChild("MainGame"):WaitForChild("PlayerData"):FindFirstChild(player.Name).Equipped.Value ~= nil then
local equippedVal = serverStorage:WaitForChild("MainGame"):WaitForChild("PlayerData"):FindFirstChild(player.Name).Equipped
dataStore:SetAsync("equipped-"..player.UserId, equippedVal.Value)
end
local plrRewards = player:WaitForChild("RewardsClaimed"):GetChildren()
local rewardsTable = {}
for _, w in pairs(plrRewards) do
table.insert(rewardsTable, w.Name)
end
dataStore:SetAsync("rewards-"..player.UserId, rewardsTable)
print("Saved "..player.Name.."'s Data.")
end)
end
function plrStats.AntiBan(player, reason)
player.IsBanned.Value = true
player.IsBanned.Reason.Value = "You have been banned by the Anti-Cheat. Reason: "..reason..". This ban is permanent"
player:Kick(player.IsBanned.Reason.Value)
end
return plrStats
Server:
Players.PlayerAdded:Connect(function(player)
playersLeft += 1
leaderstats.LoadData(player)
end)
Players.PlayerRemoving:Connect(function(player)
playersLeft -= 1
leaderstats.SaveData(player)
end)
----
----
game:BindToClose(function()
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)
Practically the same code. It’s so strange.