To start things off, I’m extremely stumped and I’ve had to compensate 3 people already because of this, so I’m kind of playing with people’s money here.
I have a gamepass script that rewards a player then updates whether they have already been rewarded or not. Yet, the “AlphaPromise” bool value isn’t being changed. It rewards and everything, sometimes it changes, other times it doesn’t, and then sometimes it doesn’t reward at all even with the value being false.
Here’s the code:
-- Establishing the locations of the player stats
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 7759390
local function onPlayerAdded(player)
local playerfolder = game.ServerStorage.Players:WaitForChild(player.Name)
local GamePassFolder = playerfolder:WaitForChild("GamePasses")
local AlphaPromise = GamePassFolder:FindFirstChild("AlphaPromise")
local Credits = playerfolder:WaitForChild("Credits")
local Skins = playerfolder:WaitForChild("Skins")
Here’s the default roblox gamepass code:
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
-- It properly finds the AlphaPromise Value and rewards, yet doesn't change the value to true. Or sometimes doesn't reward at all.
if hasPass == true then
if AlphaPromise.Value == false then
Credits.Value = Credits.Value + 7500
Skins.Alpha.Value = true
AlphaPromise.Value = true
elseif AlphaPromise.Value == true
then
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
I’m genuinely puzzled. I don’t know if this is a Roblox Engine bug, or I’m doing something wrong with the code. I even tried adding WaitForChilds to make sure it wasn’t looking for nonexistent things. Any help?
Yep, which adds to the confusion. I’ve tested it almost 40 times now and it’s a 50/50 chance that it’ll reward, and if it does reward it doesn’t update the bool value. It’s the oddest thing I’ve ever come across.
So I decided to duplicate the script and see what would happen and sure enough it fixed itself. The code is completely identical, it’s just copy and pasted into a fresh server script. I can’t even express how confused I am about this. I’ve tested it over and over and it hasn’t failed yet. Should I rule this as an engine bug? It’s not the first time I’ve had issues with server scripts not working for no reason at all until I literally put the code into a fresh script.
The last time I had an issue like this, no matter how much code I changed in the script, it reset itself as soon as I closed it. It might be a new engine bug.
The WaitForChild function is what I normally recommend to not rely on, based on my experience. As it waits for the child as named, but never really does anything next. I’d delay the script on the first line with:
wait(1)
So it can let the game load first then call each object, and as expected, it’ll be found.
That’s my way, so I don’t have to use :WaitForChild.
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if success then
if hasPass == true then
if AlphaPromise.Value == false then
Credits.Value = Credits.Value + 7500
Skins.Alpha.Value = true
AlphaPromise.Value = true
end
end
else
warn("Error while checking if player has pass: " .. tostring(message))
end
@APointProven
Probably not the answer, but you could reduce your code doing the above this way instead
if hasPass==true and AlphaPromise.Value == false
then
Also where you do :
if hasPass == true then
unless this code runs after a purchase is prompted and hasPass is set to true (which I don’t see in your code), hasPass will remain false as defined earlier, so after the line (where you attempt change the value) if hasPass == true then
will not run at all
“AlphaPromise” is only being changed to true, if what you meant is it doesnt go to false theres a fix.
But if that isnt it the possibility that something else is changing it also exists, make sure no other script is messing with that value. And this is important, always make sure its replicated to server and client. If the value is in serverstorage it wont be replicated to everyone.