Problem with the Value in the script

Hello Everyone!, So the problem is very simple,

yeah so there is a “VIP” value in the player and this script is making that VIP folder to true if the player purchased the pass

but when i see the value it shows false!

local function playeradded(player)
	for i, v in gamepassproduct do
		print("Step1")
	local hasPass = false
	
	local sucess , errormsg = pcall(function()
			hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, v.ID)
			print("Step 2")
		end)
		if hasPass then
			print("Step 3")
		end
	
		if hasPass then
			print("step 4")
			if v.ID == VIPid then
				
				local vipvalue = player:WaitForChild("VIP")
				vipvalue.Value = true
				if vipvalue.Value == true then
					print("Step 5")
				end
			end
		
		
	end
	if not sucess and hasPass then
		warn(errormsg)
		end
		end
end

image

3 Likes

How many steps did it print? If it doesn’t print step 3, 4 and 5 then you didn’t purchase the gamepass, try after buying the gamepass fire this function again

2 Likes

it prints all the steps! but it does not change the value

1 Like

Considering this is a VIP Pass storing that information on the player is bound to get hacked. This is something you would want secure. Even if that means calling a from a few scripts. This is a short way to get that information securely. Ideally you would only want to call this once on spawn(s).

-- server script in ServerScriptService 

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassID = 123456789

function Spawned(player)
	task.wait(1.1) local HasGamepass = false
	local success, message = pcall(function()
		HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
	end) if not success then warn(tostring(message)) return end -- shows error to warn
		
	if HasGamepass then
--		print(true)
		
		--
		-- your vip adds
	    -- game.ServerStorage.Tools.Grenade2:Clone().Parent = player.Backpack
		--
		
--	else print(false) 
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		Spawned(player)
	end)
end)
1 Like

Hey, I looked at this script and i notice that isn’t it is same? And btw i asked for help with value of “VIP” but even this script is ok but they look the same? How it is going to protect it?

2 Likes

You see that part that says “if HasGamepass then”

if HasGamepass then
   local vipvalue = player:WaitForChild("VIP")
   vipvalue.Value = true
end

“How it is going to protect it?”
This is all handled in an untouchable ServerScriptService Script. You protect it by not making available to hackers. As I said holding it in a bool on the player isn’t secure. Adding these lines blows all hope of that … Take care of your VIP adds in that script.

2 Likes

Yeah but it is also same here also? this is in serverscriptservice!

	if hasPass then
			if v.ID == VIPid then
				local vipvalue = player:WaitForChild("VIP")
				vipvalue.Value = true
			end
2 Likes

Yeah then is there any other way to secure the values without using boolvalues or making them untouchable by the exploiters?

2 Likes

You asked for help with VIP, I give you good advice and a way to do it and also gave you a way to do like you were that works.

2 Likes

Hey i told that “VIP” Values does not becomes true! i am not talking about securing!

2 Likes

VIP probably isn’t there yet. Add the bool in this script after if hasPass …

2 Likes

Yeah so when played the vip value does not change!

1 Like

You want it on player or player.Character?

2 Likes

So this script is in serverscript and this changes the value of vip in the player adn if they have the gamepass then it will change to true but here it does not change to true and remains false!

1 Like

Where is this VIP bool at in player or in player.Character ?

1 Like

it is in the player! like how you would put leaderstats in the player.

1 Like

If you would still like to use the boolvalue (Which in my eyes won’t harm as of now since its on the serverside and can only be read and not modified by exploiters) You can try this code.

Hopefully it works for you, Feel free to let me know if it doesnt! :+1:

local MarketplaceService = game:GetService("MarketplaceService")
local VIPid = "" -- Replace with your VIP game pass ID
local function playeradded(player)
    for i, v in ipairs(gamepassproduct) do
        print("Checking game pass:", v.ID)
        
        local hasPass = false
        local success, errorMessage = pcall(function()
            hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, v.ID)
        end)
        
        if success then
            print("Game pass check successful for:", v.ID)
            if hasPass then
                print("Player owns the game pass:", v.ID)
                if v.ID == VIPid then
                    local vipvalue = player:FindFirstChild("VIP")
                    if vipvalue then
                        vipvalue.Value = true
                        if vipvalue.Value == true then
                            print("VIP value set to true for player:", player.Name)
                        end
                    else
                        warn("VIP value not found for player:", player.Name)
                    end
                end
            end
        else
            warn("Error checking game pass:", v.ID)
            warn(errorMessage)
        end
    end
end

game.Players.PlayerAdded:Connect(playeradded)

1 Like

Hey Now here is the problem :

if haspass then
  local vipvalue = player:FindFirstChild("VIP")
                    if vipvalue then
                        vipvalue.Value = true
end
end

So here the script should change the value of vip from false to true but it does not work out and FindFirstChild also might not work because the Vip value gets added after just few seconds so that is why i added Wait for child as it waits for it to load!

1 Like

Okay noted, change that to WaitForChild then.

Maybe debug a little more?

local vipvalue = player:WaitForChild("VIP")
if vipvalue then
    vipvalue.Value = true
    if vipvalue.Value == true then
        print("VIP value set to true for player:", player.Name)
    end
    print("Value now", vipvalue.Value)
else
    warn("VIP value not found for player:", player.Name)
end
1 Like
-- server script in ServerScriptService 

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassID = 123456789 -- Add your ID

function Spawned(player)
	task.wait(1.1) local HasGamepass = false
	local success, message = pcall(function()
		HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
	end) if not success then warn(tostring(message)) return end -- shows error to warn
		
	if HasGamepass then
		player:WaitForChild("leaderstats").VIP.Value = true
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		
--  set up to create the bool
--		local VIP = Instance.new("BoolValue")
--		VIP.Name = "VIP" VIP.Value = false 
--		VIP.Parent = player:WaitForChild("leaderstats")
		
		Spawned(player)
	end)
end)

Btw: What’s with all the !!!'s. No one here is obligated to help you at all. A bit more tact would be nice.

1 Like