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)

4 comments
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.
Nope, it gives an infinite yeild on players and breaks the rest.
code block this and then i can help
There you go, its now block coded