Greetings,
I have this code, without the player owning the gamepass everything works fine, but with it, the bonus is not applied, check the code to see what I am talking about.
local gamePassId = 106793064
local haspass1 = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, tonumber(gamePassId))
local Players = game:GetService("Players")
player = Players:GetPlayerFromCharacter(player.Parent)
if typeof(player) == "Instance" and not player:IsA("Player") then return end
if player ~= plr then return end -- It wasn't aimed at our player, ignore
if haspass1 then
SpeedValue.Value += ((value * (RebirthsValue.Value + 1)) * 2) -- Adding value with the 2x permanent boost included
else
SpeedValue.Value += (value * (RebirthsValue.Value + 1)) -- Adding value without any boosts
end
Please help me!
Your variables are kind of confusing. I’m assuming player
is a part which is from a Touched event, and it is reassigned to the actual player. I suggest doing using these variable names instead:
Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
-- your code here
end
end)
So fixed code should look similar to this:
local DoubleSpeed = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, 106793064)
Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local rebirthmulti = RebirthsValue.Value + 1
if player == plr then
if DoubleSpeed then
SpeedValue.Value += value * rebirthmulti * 2
else
SpeedValue.Value += value * rebirthmulti
end
end
end)
I don’t have any trouble with the values, I have included a bit of extra code because many ask for it, the only issue I have is this:
local gamePassId = 106793064
local haspass1 = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, tonumber(gamePassId))
if haspass1 then
SpeedValue.Value += ((value * (RebirthsValue.Value + 1)) * 2) -- Adding value with the 2x permanent boost included
else
SpeedValue.Value += (value * (RebirthsValue.Value + 1)) -- Adding value without any boosts
end
Can you tell us what you’re trying to give the player when they buy the gamepass? Without knowing more about the context in which this code is being executed, it is difficult to provide a specific solution.
When the player joins the game (this is for every player), it checks if the player owns the gamepass and if the player owns it, it makes haspass1
true (I hope that’s how it works). Then when the player gains points, when the points are added, everytime it will be checked if haspass1
is true and if it is then it will give 2x the points.