To begin with, you need to comprehend the topic thoroughly. There might be more than one solution so let me give some examples of how you may achieve it:
Inside the Player
- Every time a player joins the server, just create a value that you can store an identification, which could either be a number or a string or a boolean, preferable.
game:GetService("Players").PlayerAdded:Connect(function(player) -- The player
local value = Instance.new("BoolValue") -- BoolValue recommended
local success, returned = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassId)
end)
if success and returned then
value.Value = returned
else
value.Value = false
end
value.Parent = player
end)
Inside a Table (Recommended)
When the server starts off running, create a table where you can store an identification for each player in the server, which could be either a number or a string or a boolean, preferable.
local list = {}
game:GetService("Players").PlayerAdded:Connect(function(player) -- The player
local success, returned = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassId)
end)
if success and returned then
list[player] = returned -- I wanted to store boolean as it makes it easier to read.
else
list[player] = false
end
end)
And when you want a player to win and multiply the increase by two, acquire the table to continue with it.
local function awardPlayer(player)
if list[player] then
player.leaderstats.Wins.Value += 1
player.leaderstats.Coins.Value += 20
else
player.leaderstats.Wins.Value += 1
player.leaderstats.Coins.Value += 10
end
end
The rest of the script goes here.
function gMgr:declareWinner(player)
awardPlayer(player)
winnerRe:FireAllClients(player, declareWinnerTime)
wait(declareWinnerTime)
sessionData[player]["isWinner"] = true
sessionData[player]["win"] = sessionData[player]["wins"] + 1
for ply, data in pairs(sessionData) do
local spawnPnt = lSpawns[math.random(1, #lSpawns)]
ply.Character.HumanoidRootPart.CFrame = spawnPnt.CFrame + Vector3.new(0, 3, 0)
data["isPlaying"] = false
end
end
There is one more thing. Unregister players from the table if they quit the game.
game:GetService("Players").PlayerRemoving:Connect(function(player)
table.remove(list, player)
end)
- Note: Implement the
awardBadge
function accordingly in the first example by simply replacing the list with values that are children of the player.
As I said, those are some examples but there may be thousands of it. It depends on what you want to do.
I will end this up by summarizing it; Disconnect() seems redundant here.