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

Rebirthing System will not level people up, why won't it work?

I tried to make a rebirth system in my game everything like the multipliers and such work, except actually leveling up. I created a gui that if you click the "okay" button and you have enough coins it will level you up, but it just will not work. There's no errors, or anything. Can someone help?

Server Script:




local datastoreService = game:GetService("DataStoreService")
local CoinsDataStore = datastoreService:GetDataStore("CoinsDataStore")
local ReirthDataStore = datastoreService:GetDataStore("RebirthDataStore")
local rebithed = game.ReplicatedStorage:WaitForChild("Rebirthed")
game.Players.PlayerAdded:Connect(function(player)
	local data = Instance.new("Folder",player)
	data.Name = "Data"
	
	local folder = Instance.new("Folder",player)
	folder.Name = "Values"
	
	local coins = Instance.new("IntValue",data)
	coins.Name = "Coins" --Name "Wins" to what ever you want.
	coins.Value = 0
	
	local rebirths = Instance.new("IntValue",data)
	rebirths.Name = "Rebirths"
	rebirths.Value = 0
	
	local fake1 = Instance.new("StringValue",folder)
	fake1.Value = tostring(coins.Value)
	fake1.Name = tostring(coins.Name)
	
	local thingys = Instance.new("Folder",player)
	thingys.Name = "Thing"
	
	local required = Instance.new("IntValue",thingys)
	required.Name = "Required"
	while wait() do
		required.Value = 100  * (rebirths.Value + 1)
	end
	
	local data
	local data2
	
	local success, errormessage = pcall(function()
		data = CoinsDataStore:GetAsync(player.UserId.."-Coins")
		data2 = CoinsDataStore:GetAsync(player.UserId.."-Rebirths")
	end)
	if success then
		coins.Value = datalocal datastoreService = game:GetService("DataStoreService")
local CoinsDataStore = datastoreService:GetDataStore("CoinsDataStore")
local ReirthDataStore = datastoreService:GetDataStore("RebirthDataStore")
local rebithed = game.ReplicatedStorage:WaitForChild("Rebirthed")
game.Players.PlayerAdded:Connect(function(player)
	local data = Instance.new("Folder",player)
	data.Name = "Data"
	
	local folder = Instance.new("Folder",player)
	folder.Name = "Values"
	
	local coins = Instance.new("IntValue",data)
	coins.Name = "Coins" --Name "Wins" to what ever you want.
	coins.Value = 0
	
	local rebirths = Instance.new("IntValue",data)
	rebirths.Name = "Rebirths"
	rebirths.Value = 0
	
	local fake1 = Instance.new("StringValue",folder)
	fake1.Value = tostring(coins.Value)
	fake1.Name = tostring(coins.Name)
	
	local thingys = Instance.new("Folder",player)
	thingys.Name = "Thing"
	
	local required = Instance.new("IntValue",thingys)
	required.Name = "Required"
	while wait() do
		required.Value = 100  * (rebirths.Value + 1)
	end
	
	local data
	local data2
	
	local success, errormessage = pcall(function()
		data = CoinsDataStore:GetAsync(player.UserId.."-Coins")
		data2 = CoinsDataStore:GetAsync(player.UserId.."-Rebirths")
	end)
	if success then
		coins.Value = data
		rebirths.Value = data2
	else
		print("THERE WAS AN ERROR GETTING YOUR DATA STORE.")
		warn(errormessage)
	end
	
	while wait() do
     local x = tostring(coins.Value)
	if #x >= 14 then -- Trillions
			fake1.Value = x:sub(0,(#x-13)).."."..(x:sub(#x-11,(#x-11))).."T+"
     elseif #x >= 10 then --Billions
            fake1.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
        elseif #x >= 7 then --Millions
            fake1.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
        elseif #x >= 4 then --Thousands
            fake1.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
        else -- If it's not high enough...
         fake1.Value = tostring(coins.Value)
		end
	end
	required.OnServerEvent:Connect(function(player)
		if player.Data.Coins.Value >= required.Value then
			player.Data.Coins.Value = 0
			player.Data.Rebirths.Value = player.Data.Rebirths.Value + 1
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
	CoinsDataStore:SetAsync(player.UserId.."-Coins",player.Data.Coins.Value)
	ReirthDataStore:SetAsync(player.UserId.."-Rebirths",player.Data.Rebirths.Value)
	end)
	if success then
		print(player.Name.." data saved successfully.")
	else
		print("There was an error saving data.")
		warn(errorMessage)
	end
end)
		rebirths.Value = data2
	else
		print("THERE WAS AN ERROR GETTING YOUR DATA STORE.")
		warn(errormessage)
	end
	
	while wait() do
     local x = tostring(coins.Value)
	if #x >= 14 then -- Trillions
			fake1.Value = x:sub(0,(#x-13)).."."..(x:sub(#x-11,(#x-11))).."T+"
     elseif #x >= 10 then --Billions
            fake1.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
        elseif #x >= 7 then --Millions
            fake1.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
        elseif #x >= 4 then --Thousands
            fake1.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
        else -- If it's not high enough...
         fake1.Value = tostring(coins.Value)
		end
	end
	required.OnServerEvent:Connect(function(player)
		if player.Data.Coins.Value >= required.Value then
			player.Data.Coins.Value = 0
			player.Data.Rebirths.Value = player.Data.Rebirths.Value + 1
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
	CoinsDataStore:SetAsync(player.UserId.."-Coins",player.Data.Coins.Value)
	ReirthDataStore:SetAsync(player.UserId.."-Rebirths",player.Data.Rebirths.Value)
	end)
	if success then
		print(player.Name.." data saved successfully.")
	else
		print("There was an error saving data.")
		warn(errorMessage)
	end
end)



Local Script:




local rebirth = game.ReplicatedStorage.Rebirthed
local db = false
script.Parent.MouseButton1Click:Connect(function()
	if db == false then
		db = true
		rebirth:FireServer()
		wait(1)
		db = false
	end
end)




2 comments

0

Please include all of your code.

0

I did it

2 answers

✓ Accepted answer

There are a few errors so I just changed them. Don't need the while wait, just use .Changed.

local DataStoreService = game:GetService("DataStoreService")

local CoinsDataStore = DataStoreService:GetDataStore("CoinsDataStore")
local RebirthsDataStore = DataStoreService:GetDataStore("RebithDataStore")

game.Players.PlayerAdded:Connect(function(player)	
	local datafolder = Instance.new("Folder",player)
	datafolder.Name = "Data"
	
	local folder = Instance.new("Folder",player)
	folder.Name = "Values"
	
	local coins = Instance.new("NumberValue",datafolder)
	coins.Name = "Coins"
	
	local fake1 = Instance.new("StringValue",folder)
	fake1.Name = "Coins"
	
	local rebirths = Instance.new("NumberValue",datafolder)
	rebirths.Name = "Rebirths"
	
	local things = Instance.new("Folder",player)
	things.Name = "Thingys"
	
	local required = Instance.new("NumberValue",things)
	required.Name = "Required"
	
	local data1
	local data2
	
	local success, errormessage = pcall(function()
		data1 = CoinsDataStore:GetAsync(player.UserId.."-Coins")
		data2 = RebirthsDataStore:GetAsync(player.UserId.."-Rebirths")
	end)

	if success then
		coins.Value = data1
		rebirths.Value = data2
		required.Value = 1000 + (1 * data2)
	else
		print("THERE WAS AN ERROR GETTING YOUR DATA STORE.")
		warn(errormessage)
	end
	
	coins.Changed:connect(function(newValue)
		local x = tostring(newValue)
		if #x >= 14 then -- Trillions
			fake1.Value = x:sub(0,(#x-13)).."."..(x:sub(#x-11,(#x-11))).."T+"
		elseif #x >= 10 then --Billions
			fake1.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
		elseif #x >= 7 then --Millions
			fake1.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
		elseif #x >= 4 then --Thousands
			fake1.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
		else -- If it's not high enough...
			fake1.Value = tostring(coins.Value)
		end
	end)
	
	rebirths.Changed:connect(function(newValue)
		required.Value = 1000 + (1 * newValue)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
		CoinsDataStore:SetAsync(player.UserId.."-Coins",player.Data.Coins.Value)
		RebirthsDataStore:SetAsync(player.UserId.."-Rebirths",player.Data.Rebirths.Value)
	end)
	
	if success then
		print(player.Name.." data saved successfully.")
	else
		print("There was an error saving data.")
		warn(errorMessage)
	end
end)

game.ReplicatedStorage.Rebirth.OnServerInvoke = function(player)
	if player.Data.Coins.Value >= player.Thingys.Required.Value then
		player.Data.Rebirths.Value = player.Data.Rebirths.Value + 1
		player.Data.Coins.Value = 0
	end
end

Hello.


Problems:

  • You used == (equal to) instead of >= (equal to or greater than).

  • You used a while true do loop which would hold up the script.


Solutions:

  • You need a coroutine. Coroutines are basically a whole new script, in a single script. This means that you can use a while true do loop without holding up the rest of the script.

  • Use >= instead of ==.


Fixed Script:

local datastoreService = game:GetService("DataStoreService")
local CoinsDataStore = datastoreService:GetDataStore("CoinsDataStore")
local RebirthsDataStore = datastoreService:GetDataStore("RebithDataStore")
local Required
game.Players.PlayerAdded:Connect(function(player)
    local data = Instance.new("Folder",player)
    data.Name = "Data"

    local folder = Instance.new("Folder",player)
    folder.Name = "Values"

    local coins = Instance.new("IntValue",data)
    coins.Name = "Coins" --Name "Wins" to what ever you want.
    coins.Value = 0

    local fake1 = Instance.new("StringValue",folder)
    fake1.Value = tostring(coins.Value)
    fake1.Name = tostring(coins.Name)

    local rebirths = Instance.new("IntValue",data)
    rebirths.Name = "Rebirths"

    local things = Instance.new("Folder",player)
    things.Name = "Thingys"

    local required = Instance.new("IntValue",things)
    required.Name = "Required"
    required.Value = Required

    local data
    local data2

    local success, errormessage = pcall(function()
        data = CoinsDataStore:GetAsync(player.UserId.."-Coins")
        data2 = RebirthsDataStore:GetAsync(player.UserId.."-Rebirths")
    end)

    if success then
        coins.Value = data
        rebirths.Value = data2
    else
        print("THERE WAS AN ERROR GETTING YOUR DATA STORE.")
        warn(errormessage)
    end

	coroutine.wrap(function()
	    while wait() do
	
	     local x = tostring(coins.Value)
	    if #x >= 14 then -- Trillions
	            fake1.Value = x:sub(0,(#x-13)).."."..(x:sub(#x-11,(#x-11))).."T+"
	     elseif #x >= 10 then --Billions
	            fake1.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
	        elseif #x >= 7 then --Millions
	            fake1.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
	        elseif #x >= 4 then --Thousands
	            fake1.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
	        else -- If it's not high enough...
	         fake1.Value = tostring(coins.Value)
	end
	    end
	end)()

	coroutine.wrap(function()
	    while wait() do
	        Required = 1000 + (1*rebirths.Value)
	    end
	end)()

    game.ReplicatedStorage.Rebirth.OnServerInvoke = function()
        if player.Coins.Value >= Required then
            rebirths.Value = rebirths.Value + 1
            coins.Value = 0
        end
    end
end)
game.Players.PlayerRemoving:Connect(function(player)

    local success, errorMessage = pcall(function()

    CoinsDataStore:SetAsync(player.UserId.."-Coins",player.Data.Coins.Value)

    RebirthsDataStore:SetAsync(player.UserId.."-Rebirths",player.Data.Rebirths.Value)
    end)
    if success then

        print(player.Name.." data saved successfully.")

    else
        print("There was an error saving data.")

        warn(errorMessage)

    end
end)



5 comments

0

now what about the required amount?

0

Do you want the player to rebirth only if they have the required amount, or equal to or greater than it?

0

equal to or greater. but when i looked at the "Required" value it has not changed at all

0

coroutines make a new thread. if you want the vocab. And yes, they almost function like a completely new script.

0

ok i fixed it so it works now, but it still won't work.

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