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

leaderstats not a valid member of intvalue + leaderboard not showing at top right?

I asked a question related to these scripts a bit ago, about a nil argument. Again, these scripts are causing problems, and I can't for the life of me fix any of the errors, or understand why it is causing the error. Here is the script I'm referring to, that brings up the "leaderstats is not a valid member of IntValue":

local amount = 2
local timedelay = 2.33
local currencyname = "Cash"
wait(1)
while true do
	wait(timedelay)
	for i,v in pairs(game.ServerStorage.PlayerCash:GetChildren()) do
		if v:FindFirstChild("leaderstats") and v then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
	end
end

the leaderstats come from this script:

function FindEmptyTycoon()
	for i,v in pairs(workspace.Tycoons:GetChildren()) do
		if v.TycoonInfo.Owner.Value == nil then
			return v
		end
	end
	return nil
end


game.Players.PlayerAdded:Connect(function(Player)
	local Tycoon = FindEmptyTycoon()
	Tycoon.TycoonInfo.Owner.Value = Player
	
	
	local stats = Instance.new("BoolValue",Player)
	stats.Name = "leaderstats"
	stats.Parent = game.ServerStorage
	
	local Cash = Instance.new("IntValue",stats)
	Cash.Name = Player.Name
	Cash.Value = 0
	Cash.Parent = game.ServerStorage.PlayerCash
end)


the tycoon works fine, if I change the IntValue stored in the PlayerCash Folder in ServerStorage, I can purchase an item using this:

local TycoonInfo = script.Parent:WaitForChild("TycoonInfo")
local OwnerValue = TycoonInfo:WaitForChild("Owner")
local Buttons = script.Parent:WaitForChild("Buttons")
local Purchases = script.Parent:WaitForChild("Purchases")

local Objects = {}

function validateHitByOwner(Hit)
	if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Player and OwnerValue.Value==  Player then
			return true
		end
	end
	return false
end

for i,v in pairs(Buttons:GetChildren()) do
	local Object = Purchases:FindFirstChild(v.Object.Value)
	if Object then
		Objects[Object.Name] = Object:Clone()
		Object:Destroy()
		
		if v:FindFirstChild("Dependency") then
			coroutine.resume(coroutine.create(function()
				v.Button.Transparency = 1
				v.Button.BillboardGui.Enabled = false
				v.Button.CanCollide = false
				if Purchases:WaitForChild(v.Dependency.Value,90000) then
					v.Button.Transparency = 0
					v.Button.CanCollide = true
					v.Button.BillboardGui.Enabled = true
				end
			end))
		end
		local DB = false
		v.Button.Touched:Connect(function(Hit)
			if validateHitByOwner(Hit)then
				if DB == false then
					DB = true
					if v.Button.Transparency == 0 then
						local Purchased = DoPurchase(Hit,v,v.Price.Value,Objects[v.Object.Value])
						if Purchased then
							warn("Purchased")
						else
							warn("Can't purchase")
						end
					end
					DB = false
				end
			end
		end)
	end
end

function DoPurchase(Hit,Button,Cost,Object)
	if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Player and OwnerValue.Value == Player then
			local CashValue = game.ServerStorage.PlayerCash:FindFirstChild(Player.Name)
			if CashValue then
				if CashValue.Value >= Cost then
					CashValue.Value = CashValue.Value - Cost
					Object.Parent = Purchases
					Button:Destroy()
					return true	
				end	
			end
		end
	end
	return false
end

Edit: Okay, so I tried storing Cash(IntValue) in leaderstats(StringValue) in Players.(player's name here) and then writing this on line 60 and below on the third script:

local PlayerName = game.Players:FindFirstChild(Player)
local CashValue = game.Players.PlayerName.leaderstats:FindFirstChild("Cash")

However, when I try to run that script, as soon as I touch the button to purchase an item, it tells me that "PlayerName is not a valid member of Players".

8 comments

0

leaderstats need to be a child of player object, the rest of script is working

0

How would I go about doing that? Setting stats.Parent to Player?

0

leaderstats should be a folder if you want it to show up

0

where do i put the folder, what do i need to write in the script?

0

Create a folder called leaderstats and set it's parent to Player

0

and do i leave the code as is or?

0

Why are you storing stats in server storage? try storing it in player..

0

do i store it in Players or Players.(playername)?

1 answer

Thanks to the people in the comments, I've fixed this issue. However, another error is coming up, which I will ask in a different post.

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