Basicly all players with this game pass they will get x2 money on kills. I was testing with my alt and I got the game pass on my main I tried to kill my alt and I got +5 money making one kill (but players with the game get +10 making one kill)
the script:(ServerScriptService)
local Players = game:GetService("Players")
local MS = game:GetService("MarketplaceService")
local id = 21918888
local isVip = false
Players.PlayerAdded:Connect(function(player)
if MS:UserOwnsGamePassAsync(player.UserId,id) then
local isVip = true
end
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
if humanoid:FindFirstChild("creator") then
local FindPlayer = humanoid:FindFirstChild("creator").Value
FindPlayer.toolLeaderstats.Credits.Value += 5
elseif isVip == true then
local FindPlayer = humanoid:FindFirstChild("creator").Value
FindPlayer.toolLeaderstats.Credits.Value += 10
end
end)
end)
end)
local Players = game:GetService("Players")
local MS = game:GetService("MarketplaceService")
local id = 21918888
Players.PlayerAdded:Connect(function(player)
local isVip = false
if MS:UserOwnsGamePassAsync(player.UserId,id) then
isVip = true
end
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
if humanoid:FindFirstChild("creator") then
local FindPlayer = humanoid:FindFirstChild("creator").Value
FindPlayer.toolLeaderstats.Credits.Value += 5
elseif isVip == true then
local FindPlayer = humanoid:FindFirstChild("creator").Value
FindPlayer.toolLeaderstats.Credits.Value += 10
end
end)
end)
end)
The problem is in the way you wrote your if statement to check if the credit value should double or not. If you read out the statements in English you’ll get a sense of why this doesn’t work.
“If there’s a creator object in the Humanoid, give 5 credits. Otherwise if it doesn’t exist, then if the player is a VIP, give 10 credits.”
Assuming your kill tools always create a creator object in Humanoids to designate the killer then this creator tag hypothetically always exists after a kill so it’ll always pass the first if statement and award 5 credits. If a creator tag didn’t exist in the Humanoid, then it’d check for VIP status, but this would be pointless because your code would error given that you’re assuming a creator tag exists and indexing properties of it.
You only need to check for the creator tag once at the top. You can then apply the additional value below, whether it’s just a simple statement or a more broader check.
humanoid.Died:Connect(function ()
local creator = humanoid:FindFirstChild("creator")
-- If a creator tag doesn't exist, don't do anything
if not creator then return end
local findPlayer = creator.Value
-- If creator's value is somehow empty, don't assume it exists, cancel out
if not findPlayer then return end
-- A simple, quick way to apply your double currency pass
local multiplier = isVip and 2 or 1
local creditsGain = 5 * multiplier
-- Now apply the extra currency! Though this code also has the problem
-- of assuming certain values exist, unless your code can guarantee it will.
-- That part will be up to you to fix if you run into such issues.
findPlayer.toolLeaderstats.Credits.Value += creditsGain
end)
Yeah, I realised your second issue is that you’re using an isVip variable that’s global to everyone for some reason as an upvalue and then you have a game pass ownership check that declares an isVip variable in the if statement which goes unused and garbage collected when it goes out of scope, so the issue there is incorrectly determining if a player is a VIP or not. Find another way to track VIP status, such as an attribute on the player or a dictionary in your script of who owns VIP or not.
I tried to make print() on line 10 for see if the player got the gamepass and nothing that can be the problem, the script dont see if the player have vip.
Please read the above reply again to understand why this is the case and how you can fix it. You’re also welcome to do some research on the Developer Hub for any API uses you’re confused of or for any reference material you need to make an attempt at fixing this problem.
Your isVip variable should not be global to everyone and the redeclaration of it in the if statement doesn’t do anything because it gets cleaned when the variable goes out of scope, which is after the end. Find a different way to track the player’s VIP status.
local Players = game:GetService("Players")
local MS = game:GetService("MarketplaceService")
local id = 21918888
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
if humanoid:FindFirstChild("creator") then
local FindPlayer = humanoid:FindFirstChild("creator").Value
if MS:UserOwnsGamePassAsync(FindPlayer.UserId,id) then
FindPlayer.toolLeaderstats.Credits.Value += 10
else
FindPlayer.toolLeaderstats.Credits.Value += 5
end
end
end)
end)
end)
I was testing something like that and works. thats works too the problem is the double cash doesnt go to the player with the game pass like: all players with no game pass they get 10 credits and players with game pass get 5 credits basically it’s the reverse.