Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
Thanks this worked! All i needed to do was add another Parent? Wow now i feel dumb lol badfancy90lo 7 — 3y
Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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 :))))))))))))))))))))))))))))))))))))))))))))))))))))))

0
come that rat acediamondn123 147 — 3y

Answer this question