Attempt to index nil with 'Rebirths'

yeah, I sended a different script here too

that was the whole script? Im making edits it should be fixed in a few mins reading adjusting here n there

1 Like

I made edits here and there

From Da Top
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local DataStoreService = game:GetService('DataStoreService')
local Players = game:GetService('Players')

local UpgradeSaveRemote = ReplicatedStorage.Events:WaitForChild('UpgradeSaveRemote')
local RebirthEvent = ReplicatedStorage.Events:WaitForChild('RebirthEvent')

local DataStore = DataStoreService:GetDataStore("DataStore") --// This could be named anything 

Just wanted to let ya know going forward Datastore can be named anything :stuck_out_tongue:

PlayerAdded Event
Players.PlayerAdded:Connect(function(Player)

	local Leaderstats = Instance.new("Folder", Player)
		Leaderstats.Name = 'leaderstats'

	local Freakiness = Instance.new('NumberValue', Leaderstats)
		Freakiness.Name = 'Freakiness'
		Freakiness.Value = 0

	local Rebirths = Instance.new('NumberValue', Leaderstats)
		Rebirths.Name = 'Rebirths'
		Rebirths.Value = 0

	local PlayerValues = Instance.new('Folder', Player)
		PlayerValues.Name = 'PlayerValues'

	local Multiplier = Instance.new('IntValue', PlayerValues)
		Multiplier.Name = 'Multiplier'
		Multiplier.Value = 1

	local RebirthCost =  Instance.new('IntValue', PlayerValues)
	RebirthCost.Name = 'RebirthCost'
	RebirthCost.Value = 3

	-- Upgrades saving
	local UpgradeStatus = Instance.new('Folder', Player)
	UpgradeStatus.Name = 'UpgradeStatus'
	local function createUpgrade(UpgradeName)
		local isUpgradeBought = Instance.new('BoolValue', UpgradeStatus)
		isUpgradeBought.Name = UpgradeName
	end
	local isUpgradeBought1 = 	createUpgrade('Freaky cat')
	local isUpgradeBought2 = 	createUpgrade('Freaky Bob')
	local isUpgradeBought3 = 	createUpgrade('Alien freak')
	local isUpgradeBought4 = 	createUpgrade('Eater')
	local isUpgradeBought5 = 	createUpgrade('Freaky Freddy')
	local isUpgradeBought6 = 	createUpgrade('Quincy freak')
	local isUpgradeBought7 = 	createUpgrade('Mahito freak')
	local isUpgradeBought8 = 	createUpgrade('Extra freaky Bob')

	UpgradeSaveRemote.OnServerInvoke = function(player, UpgradeValue, UpgradeName)
		Player.UpgradeStatus[UpgradeName].Value = UpgradeValue
		return Player.UpgradeStatus[UpgradeName].Value

	end

	--// Data DataRetrival - Getting/Fetching data
	local DataTable = DataStore:GetAsync(Player.UserId)
	if DataTable then
		Freakiness.Value = DataTable[1]
		isUpgradeBought1.Value = DataTable[2]
		isUpgradeBought2.Value = DataTable[3]
		isUpgradeBought3.Value = DataTable[4]
		isUpgradeBought4.Value = DataTable[5]
		isUpgradeBought5.Value = DataTable[6]
		isUpgradeBought6.Value = DataTable[7]
		isUpgradeBought7.Value = DataTable[8]
		isUpgradeBought8.Value = DataTable[9]
		if DataTable[10]  == nil then --//Detecting Rebirths
			Rebirths.Value = 0 --// Or Defaul values
			Multiplier.Value = 0 --// Or Default
			RebirthCost.Value =  0 --// Or Default
		else --// There is data so...
			Rebirths.Value = DataTable[10]
			Multiplier.Value = DataTable[11]
			RebirthCost.Value = DataTable[12]
		end

	else --// Player has no data AHHHHH! set default
		local DefaultData = {
			Freakiness.Value,
			isUpgradeBought1.Value,
			isUpgradeBought2.Value,
			isUpgradeBought3.Value,
			isUpgradeBought4.Value,
			isUpgradeBought5.Value,
			isUpgradeBought6.Value,
			isUpgradeBought7.Value,
			isUpgradeBought8.Value,
			Rebirths.Value,
			Multiplier.Value,
			RebirthCost.Value
		}
		DataStore:GetAsync(Player.UserId, DefaultData)
	end
end)

I never commented this but I think you can add it back no probs idk if it would work :face_with_spiral_eyes:

--RebirthEvent.OnServerEvent:Connect(function(Player, RebSave, MultSave)

	--	local leaderstats = Player:WaitForChild('leaderstats')
	--	local Multiplier = Player.PlayerValues:WaitForChild('Multiplier')
	--	local RebirthCost = Player.PlayerValues:WaitForChild('RebirthCost')

	--	leaderstats.Freakiness.Value = 0
	--	leaderstats.Rebirths.Value += 1

	--	Multiplier.Value += 0.5
	--	RebirthCost.Value *= 2
	--	print('Rebirth cost server: '..RebirthCost.Value)
	--end)

I didn’t touch the rest just the top and uncommented runs some test check for errors ill be here for a bit to assist so let me know…

1 Like

Thank you for this code, but upgrade cost still doesnt change from 0:
image
image

Also some client code:

local Rebirths = Leaderstats.Rebirths

local PlayerValues = Player:WaitForChild('PlayerValues')
local RebirthCost = PlayerValues:WaitForChild('RebirthCost')
local Multiplier = PlayerValues:WaitForChild('Multiplier')

BuyButton.MouseButton1Click:Connect(function()
	
	if Freakiness.Value >= RebirthCost.Value then
		
		RebirthCost.Value *= 2
		Multiplier.Value += 0.5
		
		RebirthsFrame.Visible = false
		
		RebirthEvent:FireServer(RebirthCost.Value, Multiplier.Value)
		print('Rebirth cost: '..RebirthCost.Value)
		
	end
	
end)

sorry I forgot I was helping you looking at the code rn

Edit: So I’m seeing here on the client that it’s still zero, and then on the server, it’s zero. assuming this is all the code you need to debug better

print ( Freakiness.Value, RebirthCost.Value ,  Freakiness.Value >= RebirthCost.Value  )
if Freakiness.Value >= RebirthCost.Value then
print ( Freakiness.Value, RebirthCost.Value  )

I have a feel your conditional isn’t working the way you intended it to.

image
yeah I dont even know where it turns to zero :sob:

Oh,'m dum why are doing this *= never used it but I assume it’s multiplying and you know basic multiplication I’m assuming

everything times zero is…. zero