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

How to define player in DataStore 2 for rebirths?

Asked by 5 years ago
Edited 5 years ago

I was trying to define a player in a leaderstats DataStore2 script for rebirths since if i use

if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Rebirths") player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1

This wouldn't work since my DataStore2 script prevents updated values in the IntValue in the leaderstats folder of a player. I wanted to use RebirthStore:Increment(1, defaultValue) in a DataStore2 script. I've created this and it keeps saying Player is not a valid member of Players. Basically i need help in designing a way to define players in this script.

local Player = game:GetService("Players"):GetPlayers()
game.Players.Player:WaitForChild("PlayerGui").ScreenGui.Frame.TextButton.MouseButton1Down:Connect(function(player)
    local RebirthStore = DataStore2("Rebirths", player)
    local Player = game:GetService("Players"):GetPlayers()
    local ItemStore = DataStore2("Items", player)
    local RebirthStore = DataStore2("Rebirths", player)
    local CashStore = DataStore2("Cash", player)
    local TotalStore = DataStore2("Total", player)
        for p in ipairs(Player) do
            if Player.leaderstats.Cash.Value >= 14 then
               RebirthStore:Increment(1, defaultValue)
               CashStore:Set(0)
               ItemStore:Set(0)
               script.Parent.Parent.Visible = false
            elseif Player.leaderstats.Cash.Value <= 14 then
        script.Parent.Text = "Cant Afford!"
        script.Parent.TextColor3 = Color3.fromRGB(255, 0, 0)
        wait(1)
        script.Parent.Text = "Rebirth?"
        script.Parent.TextColor3 = Color3.fromRGB(85, 0, 127)


        end
        end
        end)
0
Have you thinked about the player not entering the game when the script is fired? Maybe the script is running BEFORE the player joins and it says player isn't there yet. Try using WaitForChild to wait for the player to join the game. User#27525 1 — 5y
0
Nope, it gives an infinite yeild on players and breaks the rest. RebornedInFire 35 — 5y
0
code block this and then i can help Gameplayer365247v2 1055 — 5y
0
There you go, its now block coded RebornedInFire 35 — 5y

1 answer

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

Your problem is that u don't use game.Players.Player if Player is a variable! Use game.Players[Player] If thats a script u don't use PlayerGui on it

Ad

Answer this question