So I'm trying to make it so when a button on a gui is clicked it sends a signal to the remote event. If the player has enough coins to rebirth it does the following: resets coins, gives 10 rebirth tokens. But what I'm having an error on is when I am trying to delete all the coins bought, it won't delete. Please help me find the solution to this error.

Error: attempt to index local 'Rebirths' (a nil value)

game.ReplicatedStorage.RemoteEvents.Rebirth.OnServerEvent:Connect(function(plr)
	local rebirths = plr.leaderstats.Rebirths
	local str = plr.leaderstats.Coins
	local neededStr = (rebirths.Value + 1) * 15000000
	local rt = plr.leaderstats.Rebirths.RebirthTokens
	
	if str.Value >= neededStr then
		rebirths.Value = rebirths.Value + 1
		rebirths.Boost.Value = rebirths.Boost.Value + 1
		plr.leaderstats.Rebirths.RebirthTokens.Value = plr.leaderstats.Rebirths.RebirthTokens.Value + 10
		plr.ItemEquipped.Value = "Bronze Coin"
		local items = plr.Items
		items:WaitForChild("Bronze Coin").Parent = plr
		local ri = plr.Items:GetChildren()
		ri:Destroy()
		plr:WaitForChild("Bronze Coin").Parent = plr.Items
		str.Value = 0
		plr:LoadCharacter()
	end
end)

7 comments

0

What line?

0

Rebirths doesnt exist then. what your referencing doesnt exist

0

did you make a leaderstats script

0

Line 15

0

And yes I did make a leaderstats script

0

Never mind guys I fixed it. Thanks for wanting to help!