Getting bool value from inside game.Players player

I am making a shop that has saves when you leave, but when trying to update the shop when the player joins I am having issues getting the values. (Inside updateShop function)

–Made by Its4Realzies with help from zamd157 and
local sP = script.Parent
local player = game:GetService(“Players”).LocalPlayer

–Text colors
local red = Color3.fromRGB(221, 57, 57)
local yellow = Color3.fromRGB(245, 184, 41)
local grey = Color3.fromRGB(145, 145, 145)

–Lock, Unlock and Own item
local function updateItem(item, status)

local parentFrame = item

if status == "Owned" or status == "Locked" then
	parentFrame.BuyButton.TextColor3 = grey
	parentFrame.Info.TextColor3 = grey
	parentFrame.Title.TextColor3 = grey
	parentFrame.Pic.Image = parentFrame.Pic.Unsaturated.Value
	if status == "Owned" then
		parentFrame.BuyButton.Text = "Owned"
		parentFrame.isOwned.Value = true
	else
		parentFrame.BuyButton.Text = "Locked"
		parentFrame.isLocked.Value = true
	end
else
	parentFrame.BuyButton.TextColor3 = yellow
	parentFrame.Info.TextColor3 = yellow
	parentFrame.Title.TextColor3 = yellow
	parentFrame.Pic.Image = parentFrame.Pic.Saturated.Value
	parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	parentFrame.isLocked.Value = false
	
end

end

–Updates items in shop to owned if they are owned
local name = nil
local function updateShop()
for i = 1, 8, 1 do
if i <= 4 then
name = “It”
else
name = “Up”
end

	if player:FindFirstChild(name .. i).Value == true then
		updateItem(i, "Owned")
	end
end

end
updateShop()

local waitCheck = false
local function doPurchase(button)
local parentFrame = button.Parent

local player = game:GetService("Players").LocalPlayer
local leaderstats = player.leaderstats
local pointStat = leaderstats and leaderstats:FindFirstChild("Points")

local isOwned = parentFrame.isOwned.Value
local isLocked = parentFrame.isLocked.Value
if isOwned ~= true and isLocked ~= true then
	
	if pointStat.Value >= parentFrame.Cost.Value then
		updateItem(parentFrame, "Owned")
		pointStat.Value = pointStat.Value - parentFrame.Cost.Value
		
		--Unlocks upgrade	
		if parentFrame.isItem.Value == true then
			updateItem(sP.Store:FindFirstChild(parentFrame.Name + 4), "Unlocked") 
		end	
	elseif waitCheck ~= true then
		waitCheck = true
		parentFrame.BuyButton.TextColor3 = red
		parentFrame.BuyButton.Text = "Insufficient pts"
		wait(1)
		waitCheck = false
		parentFrame.BuyButton.TextColor3 = yellow
		parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	end
end

end

for i, button in ipairs (sP.Store:GetDescendants()) do

if button.ClassName == 'TextButton' and button.Name == "BuyButton" then

	button.MouseButton1Click:Connect(function() -- Give it an anonymous function
		doPurchase(button) -- Fire the function with the button parameter
	end)
end

end

local shopEnabled = false
–Open and close shop
local function doOpenShop()
if shopEnabled == false then
shopEnabled = true
sP.Store.Visible = true
else
shopEnabled = false
sP.Store.Visible = false
end
end

sP.StoreButton.MouseButton1Click:Connect(doOpenShop)

I am trying to get the value from a bool value inside game.Players. thatlocalplayer

so then

game.Players.LocalPlayer.[FolderOfWhatEver].bool

Oh gosh please format the code

--Made by Its4Realzies with help from zamd157 and
local sP = script.Parent
local player = game:GetService("Players").LocalPlayer

--Text colors
local red = Color3.fromRGB(221, 57, 57)
local yellow = Color3.fromRGB(245, 184, 41)
local grey = Color3.fromRGB(145, 145, 145)

–Lock, Unlock and Own item
local function updateItem(item, status)

local parentFrame = item

if status == "Owned" or status == "Locked" then
	parentFrame.BuyButton.TextColor3 = grey
	parentFrame.Info.TextColor3 = grey
	parentFrame.Title.TextColor3 = grey
	parentFrame.Pic.Image = parentFrame.Pic.Unsaturated.Value
	if status == "Owned" then
		parentFrame.BuyButton.Text = "Owned"
		parentFrame.isOwned.Value = true
	else
		parentFrame.BuyButton.Text = "Locked"
		parentFrame.isLocked.Value = true
	end
else
	parentFrame.BuyButton.TextColor3 = yellow
	parentFrame.Info.TextColor3 = yellow
	parentFrame.Title.TextColor3 = yellow
	parentFrame.Pic.Image = parentFrame.Pic.Saturated.Value
	parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	parentFrame.isLocked.Value = false
	
end
end

--Updates items in shop to owned if they are owned
local name = nil
local function updateShop()
for i = 1, 8, 1 do
if i <= 4 then
name = "It"
else
name = "Up"
end

	if player:FindFirstChild(name .. i).Value == true then
		updateItem(i, "Owned")
	end
end
end
updateShop()

local waitCheck = false
local function doPurchase(button)
local parentFrame = button.Parent

local player = game:GetService("Players").LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local pointStat = leaderstats:WaitForChild("Points")

local isOwned = parentFrame.isOwned.Value
local isLocked = parentFrame.isLocked.Value
if isOwned ~= true and isLocked ~= true then
	
	if pointStat.Value >= parentFrame.Cost.Value then
		updateItem(parentFrame, "Owned")
		pointStat.Value = pointStat.Value - parentFrame.Cost.Value
		
		--Unlocks upgrade	
		if parentFrame.isItem.Value == true then
			updateItem(sP.Store:FindFirstChild(parentFrame.Name + 4), "Unlocked") 
		end	
	elseif waitCheck ~= true then
		waitCheck = true
		parentFrame.BuyButton.TextColor3 = red
		parentFrame.BuyButton.Text = "Insufficient pts"
		wait(1)
		waitCheck = false
		parentFrame.BuyButton.TextColor3 = yellow
		parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	end
end
end

for i, button in ipairs (sP.Store:GetDescendants()) do

if button.ClassName == 'TextButton' and button.Name == "BuyButton" then

	button.MouseButton1Click:Connect(function() -- Give it an anonymous function
		doPurchase(button) -- Fire the function with the button parameter
	end)
end
end

local shopEnabled = false
--Open and close shop
local function doOpenShop()
if shopEnabled == false then
shopEnabled = true
sP.Store.Visible = true
else
shopEnabled = false
sP.Store.Visible = false
end
end

sP.StoreButton.MouseButton1Click:Connect(doOpenShop)

In this instance, you’d prob wanna use WaitForChild() to get the BoolValue from the Player object

wdym by format the code???

The code that you sent was split up in-between normal & code text

Just encase your script with 3 symbols of these ` then end your code with doing them again
1 Like

I believe this is a LocalScript, right? You can access the player via game:GetService("Players").LocalPlayer. Put it in a variable at the top of the script. Then, when accessing your value, simply index it inside the player!

...
local player = game:GetService("Players").LocalPlayer
...
player.valueName.Value
...
1 Like

This is my new code and I am getting this error:

–Made by Its4Realzies with help from zamd157 and
local sP = script.Parent
local player = game:GetService(“Players”).LocalPlayer

–Text colors
local red = Color3.fromRGB(221, 57, 57)
local yellow = Color3.fromRGB(245, 184, 41)
local grey = Color3.fromRGB(145, 145, 145)

–Lock, Unlock and Own item
local name1 = nil
local function updateItem(item, status)

local parentFrame = item

if status == "Owned" or status == "Locked" then
	parentFrame.BuyButton.TextColor3 = grey
	parentFrame.Info.TextColor3 = grey
	parentFrame.Title.TextColor3 = grey
	parentFrame.Pic.Image = parentFrame.Pic.Unsaturated.Value
	if status == "Owned" then
		parentFrame.BuyButton.Text = "Owned"
		parentFrame.isOwned.Value = true
		if item <= 4 then 
			name1 = "It"
		else
			name1 = "Up"
		end
		player:WaitForChild(name1 .. item).Value = true
		
	else
		parentFrame.BuyButton.Text = "Locked"
		parentFrame.isLocked.Value = true
	end
else
	parentFrame.BuyButton.TextColor3 = yellow
	parentFrame.Info.TextColor3 = yellow
	parentFrame.Title.TextColor3 = yellow
	parentFrame.Pic.Image = parentFrame.Pic.Saturated.Value
	parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	parentFrame.isLocked.Value = false
	
end

end

–Updates items in shop to owned if they are owned
local name2 = nil
local function updateShop()
for i = 1, 8, 1 do
if i <= 4 then
name2 = “It”
else
name2 = “Up”
end

	if player:WaitForChild(name2 .. i).Value == true then
		updateItem(i, "Owned")
	end
end

end
updateShop()

local waitCheck = false
local function doPurchase(button)
local parentFrame = button.Parent

local player = game:GetService("Players").LocalPlayer
local leaderstats = player.leaderstats
local pointStat = leaderstats and leaderstats:FindFirstChild("Points")

local isOwned = parentFrame.isOwned.Value
local isLocked = parentFrame.isLocked.Value
if isOwned ~= true and isLocked ~= true then
	
	if pointStat.Value >= parentFrame.Cost.Value then
		updateItem(parentFrame, "Owned")
		pointStat.Value = pointStat.Value - parentFrame.Cost.Value
		
		--Unlocks upgrade	
		if parentFrame.isItem.Value == true then
			updateItem(sP.Store:FindFirstChild(parentFrame.Name + 4), "Unlocked") 
		end	
	elseif waitCheck ~= true then
		waitCheck = true
		parentFrame.BuyButton.TextColor3 = red
		parentFrame.BuyButton.Text = "Insufficient pts"
		wait(1)
		waitCheck = false
		parentFrame.BuyButton.TextColor3 = yellow
		parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	end
end

end

for i, button in ipairs (sP.Store:GetDescendants()) do

if button.ClassName == 'TextButton' and button.Name == "BuyButton" then

	button.MouseButton1Click:Connect(function() -- Give it an anonymous function
		doPurchase(button) -- Fire the function with the button parameter
	end)
end

end

local shopEnabled = false
–Open and close shop
local function doOpenShop()
if shopEnabled == false then
shopEnabled = true
sP.Store.Visible = true
else
shopEnabled = false
sP.Store.Visible = false
end
end

sP.StoreButton.MouseButton1Click:Connect(doOpenShop)

Yes I am doing that now, but I am still getting errors
edit: I fixed one problem one line 24 but now I have new error

image
What’s the error? It got cut off

The name is 4 and its comparing it to 4 but its “4” can I get around that?

Simply make it “4”.
if item.Name == "4" then

1 Like

Great now there’s a new error :rofl:

Can you show what’s in the line?

1 Like

Sorry I fixed it I forgot to add name. I hope that was the last silly problem

1 Like

Ok here is model Model - Roblox line 56 if the problem I dont know how to call it I already tryed game:GetService(“Players”).LocalPlayer and I am completely stumped

To convert a string to a number you can just call tonumber() on it, and if the string is actually a number, it will convert. That way you can do this

if tonumber(item.Name) <= 4 then
   -- code
end

To fix your current error, change line 29 to this:
player:WaitForChild(name..item.Name).Value = true

1 Like
local function updateShop()
	for i = 1, 8, 1 do
		if i <= 4 then 
			name2 = "It"
		else
			name2 = "Up"
		end
		if not player:FindFirstChild(name2 .. i) then return end
		if player[name2 .. i].Value then
			updateItem(sP.Store:FindFirstChild(i), "Owned")
		end
	end
end

I believe it was because if the item wasn’t found, it would obviously error because you can’t index nil things.

1 Like