Is it possible to get the boolvalue of a player inside a module script

I have been trying to get the true or false value of a boolvalue inside of a player. I have a separate script that inserts the value and changes it to true or false if the player owns a game pass. But I’m having and issue inside of my module script. I know you cant get the local player in a module script. I’m just stuck on how i would send the players value from another script into the module script. All i literally want is the module script to get the value of boolvalue inside the player. I’ve been switching around player this and player that and I’m completely lost at this point. I’ve looked up other people who got the same errors and not a single one has worked.

Can’t you just pass the value from a script that uses the module, like in a function?

How would I do that exactly? The module script is required in the script. Would I just put the function in the script?

Module script:

function module.NeedsBoolValue(value : BoolValue)
--Do something
end

Script or LocalScript:

local boolModule = require(MyModuleScripts.BoolModule)

boolModule.NeedsBoolValue(player.Stats.BoolValue)

If i provided my module script and the function where the value would be used. Could you possibly help me implement? Im just slightly confused lol. But i get the idea of it. Still new to scripting so

Yeah you can post it here.
123456789

Module script :
(I shortened it so i dont have have 2000 characters lol)

 local TowerShop = {	
 ["Gamepass Test"] = {
		["Name"] = "Test",
		["ImageAsset"] = "rbxassetid://" ,
		["Price"] = 0 ,
		["Description"] = "Blank",
		["Event"] = Even,  -- This is the value that would be in the player. Either true or false if player owns gamepass
},
}
return TowerShop

The function where it would be used

function updateItems()
points.Text = "Points : " .. playerData.Points
limit.Text = #playerData.SelectedTowers .. "/4"

for i, tower in pairs(towers) do
	
	local oldButton = gui.Frame.Center1.List:FindFirstChild(tower.Name)
	if oldButton then
		oldButton:Destroy()
	end
	local newButton = itemsFrame:Clone()
	newButton.Name = tower.Name
	newButton.TowerName.Text = tower.Name
	newButton.Price.Text = tower.Price .. " Points"
	newButton.Image.Image = tower.ImageAsset
	newButton.Desc.Text = tower.Description
	newButton.Visible = tower.Event   -- Where the Even boolvalue would be used
	newButton.LayoutOrder = tower.Price
	newButton.Parent = gui.Frame.Center1.List
	
	local status = getItemStatus(tower.Name)
	if status == "For Sale" then
		newButton.Status.Text = "PURCHASE"
	elseif status == "Equipped" then
		newButton.Status.Text = "EQUIPPED"
		newButton.Price.Visible = false
	else 
		newButton.Status.Text = "EQUIP"
		newButton.Price.Visible = false
	end
	newButton.Status.Activated:Connect(function()
		interactItem(tower.Name)
	end)

end
end

I appreciate the help. If theres anything else id need to post please let me know

It looks like you are creating shop items that only appear if the player has a gamepass?

Yes thats what i wanna do. I have other shop items that are set to true. I just want to implement if they have a gamepass to show that item and let them equip it

Updateitems must be in a localscript then?

Yes its inside of local script inside of a gui

Then you should just obtain the BoolValue (inside the player as you said), by going through Players.LocalPlayer.

I was trying that and i kept getting an error. It wasnt seeing the BoolValue inside the player. It was saying attempt to index nil with “Even” but the BoolValue is in the player

Can you show how you did that? Also I assume you want the item to display if either:

  • The item is not an event item
  • The item IS an event item and the player has the Event gamepass

Yeah give me one sec. And yes to both your question

This is how i had it setup inside the module script at first.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Even = player.Even

game.Players.PlayerAdded:Connect(function(player)
    if MarketplaceService:UserOwnsGamePassAsync(player.UserId,24648574) then

       Even = true
  else
       Even = false

    end
end)

if player.Even is a BoolValue instance then shouldn’t it be Even.Value = true? Even = true will have no effect on the BoolValue, it will just overwrite the local variable named Even.

I changed it but still get the attempt to index nil with Even on line 4

Just thought about it tbh. You think creating a folder in Replicated storage with the players name and created that boolvalue in there would be easier than trying to get the local player? Im just not sure how to for example make Even = ReplicatedStorage and find the folder with that players name

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.