Getting an Error with my Rebirth Script

Hi, I am currently working on a rebirth system, and I have run into a little problem, I have done some research and just can’t find the solution, it keeps giving me the same error.

local RebirthModule = require(game.StarterGui.UIHandler)
local rebirthButton = script.Parent.rebirthMenu.Rebirth1
local player = game.Players.LocalPlayer
local rebirthEvent = game.ReplicatedStorage.rebirthEvent

local rebirths = {
	[1] = {Amount = 1, Cost = 100},
	[2] = {Amount = 5, Cost = 500},
	[3] = {Amount = 10, Cost = 1000},
	[4] = {Amount = 15, Cost = 5000}	
}

rebirthButton.MouseButton1Click:Connect(function()
	if player.leaderstats.Clicks >= rebirths[1].Cost then
		for i, v in pairs(rebirths:GetChildren()) do
			rebirths.Cost.Value *= 2
			rebirthEvent:FireServer()
		end
	end
end)

image

Any help will be much appreciated thank you!!!

I may be wrong but I am guessing the “Clicks” is a value. I think your forgetting .value. (i am just guessing it’s a value cuz its in leaderstats)

You forgot value

local RebirthModule = require(game.StarterGui.UIHandler)
local rebirthButton = script.Parent.rebirthMenu.Rebirth1
local player = game.Players.LocalPlayer
local rebirthEvent = game.ReplicatedStorage.rebirthEvent

local rebirths = {
	[1] = {Amount = 1, Cost = 100},
	[2] = {Amount = 5, Cost = 500},
	[3] = {Amount = 10, Cost = 1000},
	[4] = {Amount = 15, Cost = 5000}	
}

rebirthButton.MouseButton1Click:Connect(function()
	if player.leaderstats.Clicks.Value >= rebirths[1].Cost then
		for i, v in pairs(rebirths:GetChildren()) do
			rebirths.Cost.Value *= 2
			rebirthEvent:FireServer()
		end
	end
end)
1 Like

You were right on that one, but now I am getting this error.

image

local RebirthModule = require(game.StarterGui.UIHandler)
local rebirthButton = script.Parent.rebirthMenu.Rebirth1
local player = game.Players.LocalPlayer
local rebirthEvent = game.ReplicatedStorage.rebirthEvent

local rebirths = {
	[1] = {Amount = 1, Cost = 100},
	[2] = {Amount = 5, Cost = 500},
	[3] = {Amount = 10, Cost = 1000},
	[4] = {Amount = 15, Cost = 5000}	
}

rebirthButton.MouseButton1Click:Connect(function()
	if player.leaderstats.Clicks.Value >= rebirths[1].Cost then
		for i, v in pairs(rebirths) do
			rebirths.Cost.Value *= 2
			rebirthEvent:FireServer()
		end
	end
end)

image
I am getting this error now, I have tried removing .Value as well and It shows an error to

Do this instead:

local RebirthModule = require(game.StarterGui.UIHandler)
local rebirthButton = script.Parent.rebirthMenu.Rebirth1
local player = game.Players.LocalPlayer
local rebirthEvent = game.ReplicatedStorage.rebirthEvent

local rebirths = {
	[1] = {Amount = 1, Cost = 100},
	[2] = {Amount = 5, Cost = 500},
	[3] = {Amount = 10, Cost = 1000},
	[4] = {Amount = 15, Cost = 5000}	
}

rebirthButton.MouseButton1Click:Connect(function()
	if player.leaderstats.Clicks.Value >= rebirths[1].Cost then
		for i, v in pairs(rebirths) do
			rebirths.Cost.Value = game.Players["Your Folder Name"].Clicks.Value and rebirths.Cost.Value*2
			rebirthEvent:FireServer()
		end
	end
end)

I mean, if i was smart enough i can fix this bug.

You can send a LocalFile !

LocalScript.lua (683 Bytes)
Do you mean this, I am not sure lol

No, from Roblox Studio, not this file.

Video:

Sorry if this is insanely short and sorry if my text is French.

RebirthScript.lua (688 Bytes)
This is my script file right here

Changed the text a little bit.

You are trying to get the children of a table and trying to set a value that doesnt exist:

local RebirthModule = require(game.StarterGui.UIHandler)
local rebirthButton = script.Parent.rebirthMenu.Rebirth1
local player = game.Players.LocalPlayer
local rebirthEvent = game.ReplicatedStorage.rebirthEvent

local rebirths = {
    [1] = {Amount = 1, Cost = 100},
    [2] = {Amount = 5, Cost = 500},
    [3] = {Amount = 10, Cost = 1000},
    [4] = {Amount = 15, Cost = 5000}
}

rebirthButton.MouseButton1Click:Connect(function()
    if player.leaderstats.Clicks.Value >= rebirths[1].Cost then
        for i, v in pairs(rebirths) do
            v.Cost *= 2
            rebirthEvent:FireServer()
        end
    end
end)
1 Like

So how would I fix it, by removing some values?

What’s rebirths[1].Cost, a leaderstat?

no, if you want it to fire once, remove the for i, v in pairs loop

1 Like

Use @Proville6’s method and also do the following solution @Opsilu gave you. Mark @Opsilu’s reply as the solution.

EDIT: Only do this if it is this what you’re trying to achieve from us.

Yes and then all the costs go up at the same time

ahh ok, take the rebirthEvent:FireServer() out of the loop and keep the v.Cost *= 2 in the loop, that should fix it

2 Likes