What im trying to achieve :
Making a DetemineIncrement
function that will give players a certain amount of levels, and cash if they own the certain gamepasses.
What is wrong :
I’m pretty sure the way im scripting this is wrong, because It is giving the player all of the points, and way more cash if they own all the gamepasses.
My question; How would I correctly script adding levels & cash with gamepasses?
Here is my code -
local function DetermineIncrement() -- Create increment function
if (service:UserOwnsGamePassAsync(plr.UserId, VIPGamepassId)) then -- IF VIP GAMEPASS OWNER
coroutine.resume(coroutine.create(function()
while wait(60) do
LevelStore:Increment(VIPIncrement)
end
end))
coroutine.resume(coroutine.create(function()
while wait(60) do
CoinStore:Increment(math.random(15, 35))
end
end))
elseif (service:UserOwnsGamePassAsync(plr.UserId, GamepassId)) then -- IF 2X GAMEPASS OWNER
coroutine.resume(coroutine.create(function()
while wait(60) do
LevelStore:Increment(GamepassIncrement)
end
end))
coroutine.resume(coroutine.create(function()
while wait(60) do
CoinStore:Increment(math.random(5, 15))
end
end))
elseif (service:UserOwnsGamePassAsync(plr.UserId, GamepassId2)) then -- IF 3X GAMEPASS CASH OWNER
coroutine.resume(coroutine.create(function()
while wait(60) do
LevelStore:Increment(1)
end
end))
coroutine.resume(coroutine.create(function()
while wait(60) do
CoinStore:Increment(math.random(25, 45))
end
end))
else -- IF NORMAL PLAYER
coroutine.resume(coroutine.create(function()
while wait(60) do
LevelStore:Increment(1) -- Increment, meaning add, a specified amount to the datastore and update it
end
end))
coroutine.resume(coroutine.create(function()
while wait(60) do
CoinStore:Increment(math.random(5, 15))
end
end))
end
end
Keep note - I have a VIP Gamepass granting (3x levels), a 2x level gampeass, and a 3x cash gamepass.
What would be the correct way to fix this code? So they get the certain amount of levels and cash correctly, and also if they own all gamepasses they do get all the levels/cash correctly as well.
IDK if this will fix everything but if you want it to give it to the player for multiple game passes you need to make separate if statements. So just convert all of the else if and else’s to if statements. The reason for this is if/else if/else will only execute for one of them if a condition is met and then end. Multiple if statements will check for multiple values.
1 Like
Just so I’m sure I understand, if someone owns the VIP gamepass, it would increment the values every 60 seconds? I also recommend you using 2 if statements instead of elseif, because it is going to check if you have vip gamepass, if you do, it will practically skip the other gamepasses.
1 Like
Yes. Basically every minute is the waitTime
what about this code? This should do the trick, if im right. Basically just adding more increment.
local function DetermineIncrement() -- Create increment function
if (service:UserOwnsGamePassAsync(plr.UserId, VIPGamepassId)) then -- IF VIP GAMEPASS OWNER
coroutine.resume(coroutine.create(function()
while wait(waitTime) do
LevelStore:Increment(VIPIncrement)
end
end))
end
if (service:UserOwnsGamePassAsync(plr.UserId, GamepassId)) then -- IF 2X GAMEPASS OWNER
coroutine.resume(coroutine.create(function()
while wait(waitTime) do
LevelStore:Increment(GamepassIncrement)
end
end))
end
if (service:UserOwnsGamePassAsync(plr.UserId, GamepassId2)) then -- IF 3X GAMEPASS CASH OWNER
coroutine.resume(coroutine.create(function()
while wait(waitTime) do
CoinStore:Increment(math.random(25, 45))
end
end))
end
coroutine.resume(coroutine.create(function() -- IF NORMAL PLAYER
while wait(waitTime) do
LevelStore:Increment(1) -- Increment, meaning add, a specified amount to the datastore and update it
end
end))
coroutine.resume(coroutine.create(function()
while wait(waitTime) do
CoinStore:Increment(math.random(5, 15))
end
end))
end
I don’t know if this is going to work, but I gave it a go. I recommend avoiding coroutine because since you are just starting a new thread without any arguments, you can instead use spawn()
.
local hasGamepass = false
function VIPGamepass()
while wait(waitTime) do
LevelStore:Increment(VIPIncrement)
end
end
function x2Gamepass()
while wait(waitTime) do
LevelStore:Increment(GamepassIncrement)
end
end
function x3Gamepass()
while wait(waitTime) do
CoinStore:Increment(math.random(25, 45))
end
end
function noGamepasses()
while wait(waitTime) do
LevelStore:Increment(1)
CoinStore:Increment(math.random(5, 15))
end
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
if (service:UserOwnsGamePassAsync(plr.UserId, VIPGamepassId)) then
hasGamepass = true
spawn(VIPGamepass)
end
if (service:UserOwnsGamePassAsync(plr.UserId, GamepassId2)) then
hasGamepass = true
spawn(x2Gamepass)
end
if (service:UserOwnsGamePassAsync(plr.UserId, GamepassId2)) then
hasGamepass = true
spawn(x2Gamepass)
end
if not hasGamepass then
spawn(noGamepasses)
end
return
end)
1 Like