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

"leaderstats is not a valid member of PlayerGui" What does this mean?

I have gotten better at scripting but i am still getting errors and this is one of them i do npt understand and cant solve.

I am trying to make a shop gui that upgrades your weapon but it doesn't seem to detect the leaderstats. I cant understand what the error means.

Heres the script

script.Parent.MouseButton1Click:Connect(function()
	local human = workspace:FindFirstChild("Humanoid")
	print("Humanoid Found!")
	local plr = script.Parent.Parent.Parent.Parent
	print("Player Found!")
	if plr.leaderstats.Points.Value >= 24000 then
		print("checked")
		plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 24000
		script.Parent.Parent.Parent.old:Play()
		wait(1)
		script.Parent.Parent.Parent.olqa:Play()
		wait(6)
		script.Parent.Parent.Parent.olqa:Stop()
		script.Parent.Parent.Parent.buy:Play()
		game.ReplicatedStorage["PAP. Ray Gun"]:Clone().Parent = plr.Backpack
	else
		script.Parent.Text = "Inefficient Funds"
		wait(2)
		script.Parent.Text = "BUY"
	end
end)

note: the script is a local script note2: the line thats specifically causing the problems is this

	if plr.leaderstats.Points.Value >= 24000 then

I just need a way to fix this error so that the script can work correctly

2 answers

✓ Accepted answer

it happened because the Leaderstats is not the child of player gui. There should be another Parent on the plr variable. Here is a helpful video about the Server/Client Relationship and how GUI work on replicated clients.

Here you go the fixed script:

script.Parent.MouseButton1Click:Connect(function()
    local human = workspace:FindFirstChild("Humanoid")
    print("Humanoid Found!")
    local plr = script.Parent.Parent.Parent.Parent.Parent
    print("Player Found!")
    if plr.leaderstats.Points.Value >= 24000 then
        print("checked")
        plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 24000
        script.Parent.Parent.Parent.old:Play()
        wait(1)
        script.Parent.Parent.Parent.olqa:Play()
        wait(6)
        script.Parent.Parent.Parent.olqa:Stop()
        script.Parent.Parent.Parent.buy:Play()
        game.ReplicatedStorage["PAP. Ray Gun"]:Clone().Parent = plr.Backpack
    else
        script.Parent.Text = "Inefficient Funds"
        wait(2)
        script.Parent.Text = "BUY"
    end
end)

1 comment

0

Thanks this worked! All i needed to do was add another Parent? Wow now i feel dumb lol

Uhh kinda messy script but I cant explain thta well but your doing it wrong and its a bad practice.

heres an example:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local leaderstats = player:WaitForChild("leaderstats")

script.Parent.MouseButton1Click:Connect(function()
	
	if leaderstats.Points.Value >= 24000 then
 		-- enough
		print(leaderstats.Points.Value)
	else
		-- not enough
		print(leaderstats.Points.Value - 24000 .. " more points lol")
	end
end)

hope I helped :))))))))))))))))))))))))))))))))))))))))))))))))))))))

1 comment

0

come that rat

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