So I have a gamepass script that will check if the user has gamepass and then will give them money upon re spawning. I want to make it so that it will give them money as soon as they join the game, but whenever I try doing so with
game.Players.PlayerAdded:connect(function(player)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
end)
Nothing happens. This is what my current working script looks like
gpid = IDHERE -- Put your gamepass ID here
local serverstorage = game:GetService("ServerStorage")
tools = {"AssaultLaser"}
wait(2)
GPS = game:GetService("GamePassService")
function respawned(char)
player = game.Players:FindFirstChild(char.Name)
print("Respawned...")
if char:FindFirstChild("Head") ~= nil then
print("Found Player...")
if GPS:PlayerHasPass(player, gpid) then
print("Player has GPID...")
for i, v in pairs(game.Players:GetChildren()) do
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("coincurrency")
ds1:SetAsync(player.UserId, v.leaderstats.Coins.Value)
v.leaderstats.Coins.Value = v.leaderstats.Coins.Value + 10
end
for i = 1,#tools do
serverstorage:FindFirstChild(tools[i]):Clone().Parent = player.Backpack -- Where it says game.Lighting you can change to game.ServerStorage
end
else
print("Player has no GPID...")
end
end
end
game.Workspace.ChildAdded:connect(respawned)
Here is when I try adding onplayeradded
gpid = IDHERE -- Put your gamepass ID here
local serverstorage = game:GetService("ServerStorage")
tools = {"AssaultLaser"}
wait(2)
GPS = game:GetService("GamePassService")
function respawned(char)
player = game.Players:FindFirstChild(char.Name)
print("Respawned...")
if char:FindFirstChild("Head") ~= nil then
print("Found Player...")
if GPS:PlayerHasPass(player, gpid) then
print("Player has GPID...")
game.Players.PlayerAdded:connect(function(player)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
end)
for i, v in pairs(game.Players:GetChildren()) do
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("coincurrency")
ds1:SetAsync(player.UserId, v.leaderstats.Coins.Value)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
end
for i = 1,#tools do
serverstorage:FindFirstChild(tools[i]):Clone().Parent = player.Backpack -- Where it says game.Lighting you can change to game.ServerStorage
end
else
print("Player has no GPID...")
end
end
end
game.Workspace.ChildAdded:connect(respawned)
However again....this does not work. Why is this?
