Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

aaaawhy my value changing script is not working?

so i made a simple script which changes a value to player items amount.

local value = script.Parent
local plrname = game.Workspace:WaitForChild("PlayerName")
local plr = game.Players:WaitForChild(plrname.Value)
local inv = plr:WaitForChild("Inventory")
while true do
	wait(0.5)
	value.Value = #inv:GetChildren()
end

why its not working

1 answer

I think the problem is that Inventory isn't a valid member of the player. Instead, try using Backpack. Also, I would use the PlayerAdded event. This is the script I would use:

local value = script.Parent
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local backpack = player:WaitForChild("Backpack")

	local function checkForItems()
		while true do
			wait()
			value.Value = #backpack:GetChildren()
		end
	end

	spawn(checkForItems)
end)

5 comments

0

inventory is a custom folder

0

i changed backpack to the custom inventory and still not working

0

Is it a ServerScript?

0

umm no idea what serverscript is im kinda new at scripting but i guess its a normal script so - yes

0

Then idk why it's not working.

This discussion is preserved as it was. New answers, comments, and votes are closed.