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

How to define player in DataStore 2 for rebirths?

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

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.

0

Nope, it gives an infinite yeild on players and breaks the rest.

0

code block this and then i can help

0

There you go, its now block coded

1 answer

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

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