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

Cps is not a valid member of Player?

Asked by 4 years ago
Edited 4 years ago
 function addTickets(plr)
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")  
    local cps = remoteData[plr.Name].Cps
    local tickets = plr.leaderstats.Tickets
    local rebirth = plr.leaderstats.Rebirths
    while true do
        wait(1)
        tickets.Value = tickets.Value + (cps.Cps.Value + rebirth.Value)
    end
end
game.Players.PlayerAdded:Connect(addTickets)

I am trying to make a script for income, but I wanted it to be hidden and not showed on leaderstats. So I instead stored the income value in the ServerStorage under "RemoteData". When I tried to run this script, it said Cps is not a valid member of Player.

0
Also, I have another script which creates a folder of the player's name in the "RemoteData" folder and in the "RemoteData" folder there is a IntValue called Cps. tobylee1112 22 — 4y
0
I would recommend adding a WaitForChild function for Cps JoinMyWorld 2 — 4y

1 answer

Log in to vote
0
Answered by
IDKBlox 349 Moderation Voter
4 years ago

I have a couple of suggestions. Feel free to completely disregard what i'm saying if you disagree....

If you'd like things to not show up under leaderboards, you can always just add a folder within the leaderstats folder or whatever it is...

This creates a leaderstats & a hidden folder

leaderstats are under player and hidden is under the leaderstats

The cool part is... Only values under leaderstats will show.. Therefor you won't see 'Hidden' in the players leaderstats

local Players = game:GetService('Players')

Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new('Folder')
    leaderstats.Name = 'leaderstats'

    local NonHidden = Instance.new('NumberValue')
    NonHidden.Name = 'NonHidden'
    NonHidden.Value = 5
    NonHidden.Parent = leaderstats

    local hidden = Instance.new('Folder')
    hidden.Name = 'Hidden'

    local HiddenValue = Instance.new('NumberValue')
    HiddenValue.Name = 'HiddenValue'
    HiddenValue.Value = 500
    HiddenValue.Parent = hidden

    hidden.Parent = leaderstats
    leaderstats.Parent = player
end)

click this link to see the outcome of this script

the value is still going to be there although it's now hidden..

Anyways

You're not really giving enough information for us to be able to give you reliable information.

I don't know how you have your scripts set up with the leaderstats and things.. But I redid the code you gave with what I mentioned above..

I don't expect you to copy... But I do expect you to read over and learn why I did what I did.

I also have a bunch of if statements making sure things don't end up being nil, if they are then it won't cause an error, it'll just print what the issue was..

local Players = game:GetService('Players')

local function AddTickets(player,stats)
    local leaderstats = stats ~= nil and stats or player:FindFirstChild('leaderstats')
    if leaderstats then
        local hidden = leaderstats:FindFirstChild('Hidden')
        if hidden then
            local Tickets = leaderstats:FindFirstChild('Tickets')
            local Cps = hidden:FindFirstChild('Cps')
            if Tickets and Cps then
                while true do
                    leaderstats.Tickets.Value = leaderstats.Tickets.Value + hidden.Cps.Value
                    wait(1)
                end
            elseif Tickets == nil then
                print('Tickets was not found under leaderstats')
            elseif Cps == nil then
                print('CPS was not found under hidden')
            end
        else
            print('Hidden was not found under',player)
        end
    else
        print('leaderstats were not found under',player)
    end
end

Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new('Folder')
    leaderstats.Name = 'leaderstats'

    local Tickets = Instance.new('NumberValue')
    Tickets.Name = 'Tickets'
    --Tickets.Value = 5
    Tickets.Parent = leaderstats

    local Rebirths = Instance.new('NumberValue')
    Rebirths.Name = 'Rebirths'
    Rebirths.Parent = leaderstats

    local hidden = Instance.new('Folder')
    hidden.Name = 'Hidden'

    local cps = Instance.new('NumberValue')
    cps.Name = 'Cps'
    cps.Value = 1 -- whatever the starting value is
    cps.Parent = hidden

    hidden.Parent = leaderstats
    leaderstats.Parent = player
    AddTickets(player)
end)

If you have any questions at all, feel free to comment on this.

1
Instead of making another folder within leaderstats you can just name the the folder "Stats" or anything but leaderstats and it wont show up, not sure if you were aware but it all works the same way roblox just picks up on the name leaderstats and shows the within values on the player list. Si_SenorTN 25 — 4y
Ad

Answer this question