How to check if player is touching the part

im making a button simulator but im trying to make so you can just stand on button and get the Multiplier but it seems it doesnt work

			local touching = false
			--// Btn Touch
			Btn.Touched:Connect(function()
			touching = true
			end)
			Base.Touched:Connect(function()
				touching = false
			end)
			
			if touching == true then
				if db == false then
					db = true
					if Cash.Value >= Price.Value then
						Cash.Value = Cash.Value - Price.Value
						if Rebirths.Value >= 1 then
							Multiplier.Value = Multiplier.Value + MultiAdd.Value  * Rebirths.Value

						end
					end
					task.wait(.75)
					db = false
				end
				
			end
6 Likes

Dude after checking ur script, it seems that you are trying to detect when the player touches the button and update the multiplier if certain conditions are met(I hope I’m right hehehe). However, there are a few issues with the code that need to be addressed.

  1. The touching variable is being set to true or false based on whether the button is being touched. However, the subsequent code that checks the value of touching is not inside any event handler. As a result, the code will only execute once, and the touching variable will always be false. You need to place the code inside a loop or an event handler to continuously check the value.

  2. Plus dude your script doesn’t show where the db variable is declared or initialized. Make sure you declare and initialize it before using it in the script.

To address these issues, I modified your script with the solutions I said:

local touching = false
local db = false -- Declare and initialize the "db" variable

Btn.Touched:Connect(function()
    touching = true
end)

Base.Touched:Connect(function()
    touching = false
end)

while true do
    if touching then
        if not db then
            db = true
            if Cash.Value >= Price.Value then
                Cash.Value = Cash.Value - Price.Value
                if Rebirths.Value >= 1 then
                    Multiplier.Value = Multiplier.Value + MultiAdd.Value * Rebirths.Value
                end
            end
            wait(0.75)
            db = false
        end
    end
    wait(0.1) -- Adjust the wait time to your desired interval
end

In this modified script, the touching variable is continuously checked inside a loop. If the player is touching the button (touching is true), it checks the db variable to ensure the code only executes once. If the conditions are met, it updates the Cash value and increases the multiplier.

dude btw Make sure to adjust the wait time (wait(0.1)) inside the loop according to your desired time for checking the button touch.

Remember to replace Btn and Base with the actual references to the button and base parts in your game.
I hope this helps :grin:

6 Likes

db is in different parts of script also it isnt full script thats why but ill try the script

2 Likes

It’s most likely because they are being checked for once only, maybe instead add them inside a function and call the function wehn the touching value is true, something like this.

local function myFunction()	
	if touching == true then
		if db == false then
			db = true
			if Cash.Value >= Price.Value then
				Cash.Value = Cash.Value - Price.Value
				if Rebirths.Value >= 1 then
					Multiplier.Value = Multiplier.Value + MultiAdd.Value  * Rebirths.Value

				end
			end
			task.wait(.75)
			db = false
		end
	end
end		


local touching = false
--// Btn Touch
Btn.Touched:Connect(function()
	if not touching then
		touching = true
		myFunction()
	end	
end)
Base.Touched:Connect(function()
	touching = false
end)
2 Likes

Or he could create a function and put them inside then call it whenever touching is true

1 Like

Maybe explain a little more on what it is you are wanting to happen, and what is not happening.

Does the button ever turn off when a players gets off of it? Or only when ‘Base’ is touched?

Will the button and Base be affected by a single player touching it or will there be multiple players that will be touching it?

2 Likes

nvm ill just use other script since this ruined whole button system

2 Likes

Well, if you need any more help, just ask. I have done LOTS of buttons systems.

2 Likes

Okay ill explain more the system made by me which i use now requires to do /e dance or go off button and touch it again but im trying to make so you only need to stand on the button for it to give the multipliers heres full script


game.Players.PlayerAdded:Connect(function(plr)	
	--// Multis
local ButtonsFolder = game:GetService("Workspace").Buttons
	local db = false
	
for _,Button in ButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then
		--// Getting MainStats Stuff
		local MainStats = plr:WaitForChild("MainStats")
		local Multiplier = MainStats.Multipliers
			local Cash = MainStats.Cash
			local Rebirths = MainStats.Rebirths
			
		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn
			
		--//Getting Config Stuff
		local Config = Base.Config
		local MultiAdd = Config.MultiAdd
			local Price = Config.Price
			
			--// Getting Billboard stuff
			
			local bPrice = Base.Price
			local bMulti = Base.Multi
			
			--// assigning multi billboard 
			bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(124, 255, 84)
			bPrice.BillboardGui.Price.Text = "Price: "..Price.Value
			bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(255, 82, 82)
			bMulti.BillboardGui.Multi.Text = MultiAdd.Value.."+ Multiplier"
			
			
			
			--// Btn Touch
			Btn.Touched:Connect(function()
				if db == false then
					db = true
				if Cash.Value >= Price.Value then
					Cash.Value = Cash.Value - Price.Value
						if Rebirths.Value >= 1 then
							Multiplier.Value = Multiplier.Value + MultiAdd.Value  * Rebirths.Value
							
						end
					end
					task.wait(.75)
					db = false
					end
			end)
		
	end
	end
	--// Rebirths
	local RebirthButtonsFolder = game:GetService("Workspace").RebirthButtons
	local db = false

	for _,Button in RebirthButtonsFolder:GetChildren() do
		if Button:IsA("Folder")  then
			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Multiplier = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			--// Getting Button Stuff
			local Base = Button:FindFirstChild("Base")
			local Btn = Base.Btn

			--//Getting Config Stuff
			local Config = Base.Config
			local RebirthsAdd = Config.RebirthAdd
			local Price = Config.Price

			--// Getting Billboard stuff

			local bPrice = Base.Price
			local bMulti = Base.Multi

			--// assigning Rebirth billboard 
			bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(255, 82, 82)
			bPrice.BillboardGui.Price.Text = "Multiplier Requirement: "..Price.Value
			bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(0, 174, 255)
			bMulti.BillboardGui.Multi.Text = RebirthsAdd.Value.."+ Rebirths"

			--// Rebrith Btn Touch
			Btn.Touched:Connect(function()
				if Multiplier.Value >= Price.Value then
					Cash.Value = 0
					Multiplier.Value = 1
					Rebirths.Value = Rebirths.Value + RebirthsAdd.Value * Prestiges.Value
				end
			end)

		end
	end
	
	--// Prestiges
	local PrestigeButtonsFolder = game:GetService("Workspace").PrestigeButtons
	local db = false

	for _,Button in PrestigeButtonsFolder:GetChildren() do
		if Button:IsA("Folder")  then
			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Multipliers = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			--// Getting Button Stuff
			local Base = Button:FindFirstChild("Base")
			local Btn = Base.Btn

			--//Getting Config Stuff
			local Config = Base.Config
			local PrestigeAdd = Config.PrestigeAdd
			local Price = Config.Price

			--// Getting Billboard stuff

			local bPrice = Base.Price
			local bMulti = Base.Multi

			--// assigning Rebirth billboard 
			bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(0, 170, 255)
			bPrice.BillboardGui.Price.Text = "Rebirth Requirement: "..Price.Value
			bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(170, 85, 255)
			bMulti.BillboardGui.Multi.Text = PrestigeAdd.Value.."+ Prestiges"

			--// Prestige Btn Touch
			Btn.Touched:Connect(function()
				if Rebirths.Value >= Price.Value then
					Cash.Value = 0
					Multipliers.Value = 0
					Rebirths.Value = 0
					Prestiges.Value = Prestiges.Value + PrestigeAdd.Value
					
				end
			end)

		end
	end
	
	--// Ultra
	local UltraButtonsFolder = game:GetService("Workspace").UltraButtons
	local db = false

	for _,Button in UltraButtonsFolder:GetChildren() do
		if Button:IsA("Folder")  then
			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Ultra = MainStats.Ultra
			local Multipliers = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			--// Getting Button Stuff
			local Base = Button:FindFirstChild("Base")
			local Btn = Base.Btn

			--//Getting Config Stuff
			local Config = Base.Config
			local UltraAdd = Config.UltraAdd
			local Price = Config.Price

			--// Getting Billboard stuff

			local bPrice = Base.Price
			local bMulti = Base.Multi

			--// assigning Rebirth billboard 
			bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(170, 85, 255)
			bPrice.BillboardGui.Price.Text = "Prestige Requirement: "..Price.Value
			bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(81, 40, 121)
			bMulti.BillboardGui.Multi.Text = UltraAdd.Value.."+ Ultra"

			--// Prestige Btn Touch
			Btn.Touched:Connect(function()
				if Prestiges.Value >= Price.Value then
					Prestiges.Value = 0
					Multipliers.Value = 0
					Rebirths.Value = 0
					Cash.Value = 0
					Ultra.Value = Ultra.Value + UltraAdd.Value
				end
			end)

		end
	end
	end)
2 Likes

yeah the code is 194 lines so it might take some time

1 Like

So, it looks like you have 3 types of buttons but the structure on all 3 is pretty much the same.

For example

			--// Btn Touch
			Btn.Touched:Connect(function()
				if db == false then
					db = true
					if Cash.Value >= Price.Value then
						Cash.Value = Cash.Value - Price.Value
						if Rebirths.Value >= 1 then
							Multiplier.Value = Multiplier.Value + MultiAdd.Value  * Rebirths.Value

						end
					end
					task.wait(.75)
					db = false
				end
			end)

You step on this button, and if you have enough Cash.Value the button takes for payment, it will then
take the payment from you, change the multiplier, then it waits .75 and the button can be activated again. (by stepping off the button and on again, or by and animation triggering it again)

So what I think you are wanting is for the button to wait the .75, then automatically take the money and change the multiplier, if you are still standing on the button and havent moved.

Is that correct?

2 Likes

If that is correct, and you want to repeat the effect, you need to have a few things.
You need a way to know who is standing on the button.
You need a loop to check the buttons to see if they can give the points again.
You also need to have a db for each button

2 Likes

oh ill try btw im not good at scripting but ill try

2 Likes

Ok, just finished making changes, try this…

--======================================	
--==              Multis              ==
--======================================

local MultisList = {}	
local ButtonsFolder = game:GetService("Workspace").Buttons

for _,Button in ButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local MultiAdd = Config.MultiAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning multi billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(124, 255, 84)
		bPrice.BillboardGui.Price.Text = "Price: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(255, 82, 82)
		bMulti.BillboardGui.Multi.Text = MultiAdd.Value.."+ Multiplier"

		--lets store anything important to the button being pressed, into the buttonData
		buttonData.MultiAdd = MultiAdd.Value
		buttonData.Price = Price.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(MultisList,buttonData)
	end
end

local function ProcessMultis(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed

			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Multiplier = MainStats.Multipliers
			local Cash = MainStats.Cash
			local Rebirths = MainStats.Rebirths

			if Cash.Value >= buttonData.Price then
				Cash.Value = Cash.Value - buttonData.Price
				if Rebirths.Value >= 1 then
					Multiplier.Value = Multiplier.Value + buttonData.MultiAdd  * Rebirths.Value
				end
			end
		end
	end
end

--======================================	
--==              Rebirths            ==
--======================================
local RebirthsList = {}	
local RebirthButtonsFolder = game:GetService("Workspace").RebirthButtons

for _,Button in RebirthButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local RebirthsAdd = Config.RebirthAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning Rebirth billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(255, 82, 82)
		bPrice.BillboardGui.Price.Text = "Multiplier Requirement: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(0, 174, 255)
		bMulti.BillboardGui.Multi.Text = RebirthsAdd.Value.."+ Rebirths"


		--lets store anything important to the button being pressed, into the buttonData
		buttonData.Price = Price.Value
		buttonData.RebirthsAdd = RebirthsAdd.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(RebirthsList,buttonData)


	end
end

local function ProcessRebirths(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed

			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Multiplier = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			if Multiplier.Value >= buttonData.Price then
				Cash.Value = 0
				Multiplier.Value = 1
				Rebirths.Value = Rebirths.Value + buttonData.RebirthsAdd * Prestiges.Value
			end
		end
	end		

end




--======================================	
--==             Prestiges            ==
--======================================
local PrestigesList = {}	
local PrestigeButtonsFolder = game:GetService("Workspace").PrestigeButtons

for _,Button in PrestigeButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local PrestigeAdd = Config.PrestigeAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning Rebirth billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(0, 170, 255)
		bPrice.BillboardGui.Price.Text = "Rebirth Requirement: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(170, 85, 255)
		bMulti.BillboardGui.Multi.Text = PrestigeAdd.Value.."+ Prestiges"

		--lets store anything important to the button being pressed, into the buttonData
		buttonData.Price = Price.Value
		buttonData.PrestigeAdd = PrestigeAdd.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(PrestigesList,buttonData)
	end
end

local function ProcessPrestiges(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed


			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Multipliers = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			if Rebirths.Value >= buttonData.Price then
				Cash.Value = 0
				Multipliers.Value = 0
				Rebirths.Value = 0
				Prestiges.Value = Prestiges.Value + buttonData.PrestigeAdd

			end
		end
	end		

end

--======================================	
--==               Ultras             ==
--======================================
local UltrasList = {}	
local UltraButtonsFolder = game:GetService("Workspace").UltraButtons

for _,Button in UltraButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local UltraAdd = Config.UltraAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning Rebirth billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(170, 85, 255)
		bPrice.BillboardGui.Price.Text = "Prestige Requirement: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(81, 40, 121)
		bMulti.BillboardGui.Multi.Text = UltraAdd.Value.."+ Ultra"

		--lets store anything important to the button being pressed, into the buttonData
		buttonData.Price = Price.Value
		buttonData.RebirthsAdd = UltraAdd.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(UltrasList,buttonData)

	end
end

local function ProcessUltras(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed


			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Ultra = MainStats.Ultra
			local Multipliers = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			if Prestiges.Value >= buttonData.Price then
				Prestiges.Value = 0
				Multipliers.Value = 0
				Rebirths.Value = 0
				Cash.Value = 0
				Ultra.Value = Ultra.Value + buttonData.UltraAdd
			end
		end
	end		

end


local timeElapsed = 0
while true do --process buttons
	for n=1,#MultisList do
		ProcessMultis(MultisList[n],timeElapsed)
	end
	for n=1,#RebirthsList do
		ProcessRebirths(RebirthsList[n],timeElapsed)
	end
	for n=1,#PrestigesList do
		ProcessPrestiges(PrestigesList[n],timeElapsed)
	end
	for n=1,#UltrasList do
		ProcessUltras(UltrasList[n],timeElapsed)
	end

	timeElapsed = task.wait()
end

I couldnt really test because I don’t have all your instances, etc…
So if you are getting errors and you can’t figure out what is happeing, or it you just
have questions about what I have done.

Just ask, I might be offline a bit, but I will get back to you.

4 Likes

when i touch rebrith button it doesnt do anything

What about the other buttons?
Did they work?

I see the problem, its with the list at the end of the code, I didn’t put the correct function names, they are all calling ProcessMultis

image

I was in a rush yesterday, and coded the part for Multis first, then did copy paste for the rest, making changes.

This should fix that problem.

--======================================	
--==              Multis              ==
--======================================

local MultisList = {}	
local ButtonsFolder = game:GetService("Workspace").Buttons

for _,Button in ButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local MultiAdd = Config.MultiAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning multi billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(124, 255, 84)
		bPrice.BillboardGui.Price.Text = "Price: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(255, 82, 82)
		bMulti.BillboardGui.Multi.Text = MultiAdd.Value.."+ Multiplier"

		--lets store anything important to the button being pressed, into the buttonData
		buttonData.MultiAdd = MultiAdd.Value
		buttonData.Price = Price.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(MultisList,buttonData)
	end
end

local function ProcessMultis(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed

			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Multiplier = MainStats.Multipliers
			local Cash = MainStats.Cash
			local Rebirths = MainStats.Rebirths

			if Cash.Value >= buttonData.Price then
				Cash.Value = Cash.Value - buttonData.Price
				if Rebirths.Value >= 1 then
					Multiplier.Value = Multiplier.Value + buttonData.MultiAdd  * Rebirths.Value
				end
			end
		end
	end
end

--======================================	
--==              Rebirths            ==
--======================================
local RebirthsList = {}	
local RebirthButtonsFolder = game:GetService("Workspace").RebirthButtons

for _,Button in RebirthButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local RebirthsAdd = Config.RebirthAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning Rebirth billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(255, 82, 82)
		bPrice.BillboardGui.Price.Text = "Multiplier Requirement: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(0, 174, 255)
		bMulti.BillboardGui.Multi.Text = RebirthsAdd.Value.."+ Rebirths"


		--lets store anything important to the button being pressed, into the buttonData
		buttonData.Price = Price.Value
		buttonData.RebirthsAdd = RebirthsAdd.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(RebirthsList,buttonData)


	end
end

local function ProcessRebirths(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed

			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Multiplier = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			if Multiplier.Value >= buttonData.Price then
				Cash.Value = 0
				Multiplier.Value = 1
				Rebirths.Value = Rebirths.Value + buttonData.RebirthsAdd * Prestiges.Value
			end
		end
	end		

end




--======================================	
--==             Prestiges            ==
--======================================
local PrestigesList = {}	
local PrestigeButtonsFolder = game:GetService("Workspace").PrestigeButtons

for _,Button in PrestigeButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local PrestigeAdd = Config.PrestigeAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning Rebirth billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(0, 170, 255)
		bPrice.BillboardGui.Price.Text = "Rebirth Requirement: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(170, 85, 255)
		bMulti.BillboardGui.Multi.Text = PrestigeAdd.Value.."+ Prestiges"

		--lets store anything important to the button being pressed, into the buttonData
		buttonData.Price = Price.Value
		buttonData.PrestigeAdd = PrestigeAdd.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(PrestigesList,buttonData)
	end
end

local function ProcessPrestiges(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed


			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Multipliers = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			if Rebirths.Value >= buttonData.Price then
				Cash.Value = 0
				Multipliers.Value = 0
				Rebirths.Value = 0
				Prestiges.Value = Prestiges.Value + buttonData.PrestigeAdd

			end
		end
	end		

end

--======================================	
--==               Ultras             ==
--======================================
local UltrasList = {}	
local UltraButtonsFolder = game:GetService("Workspace").UltraButtons

for _,Button in UltraButtonsFolder:GetChildren() do
	if Button:IsA("Folder")  then

		--create data structure for this button
		local buttonData = {}

		--// Getting Button Stuff
		local Base = Button:FindFirstChild("Base")
		local Btn = Base.Btn

		--//Getting Config Stuff
		local Config = Base.Config
		local UltraAdd = Config.UltraAdd
		local Price = Config.Price

		--// Getting Billboard stuff

		local bPrice = Base.Price
		local bMulti = Base.Multi

		--// assigning Rebirth billboard 
		bPrice.BillboardGui.Price.TextColor3 = Color3.fromRGB(170, 85, 255)
		bPrice.BillboardGui.Price.Text = "Prestige Requirement: "..Price.Value
		bMulti.BillboardGui.Multi.TextColor3 = Color3.fromRGB(81, 40, 121)
		bMulti.BillboardGui.Multi.Text = UltraAdd.Value.."+ Ultra"

		--lets store anything important to the button being pressed, into the buttonData
		buttonData.Price = Price.Value
		buttonData.RebirthsAdd = UltraAdd.Value
		buttonData.PlayerList = {} --this is a list of players who are touching this button

		--// Btn Touch
		Btn.Touched:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				if buttonData.PlayerList[tostring(player.UserId)]  == nil then
					buttonData.PlayerList[tostring(player.UserId)] = {
						Id = player.UserId,
						Db = 0
					}
				end
			end
		end)
		Btn.TouchEnded:Connect(function(part)
			local player = game.Players:GetPlayerFromCharacter(part.Parent)
			if player then
				buttonData.PlayerList[tostring(player.UserId)] = nil
			end				
		end)

		table.insert(UltrasList,buttonData)

	end
end

local function ProcessUltras(buttonData,elapsed)
	for k,playerData in pairs(buttonData.PlayerList) do 
		local plr = game.Players:GetPlayerByUserId(playerData.Id)
		if plr and playerData.Db <= 0 then
			playerData.Db = playerData.Db - elapsed


			--// Getting MainStats Stuff
			local MainStats = plr:WaitForChild("MainStats")
			local Cash = MainStats.Cash
			local Prestiges = MainStats.Prestiges
			local Ultra = MainStats.Ultra
			local Multipliers = MainStats.Multipliers
			local Rebirths = MainStats.Rebirths

			if Prestiges.Value >= buttonData.Price then
				Prestiges.Value = 0
				Multipliers.Value = 0
				Rebirths.Value = 0
				Cash.Value = 0
				Ultra.Value = Ultra.Value + buttonData.UltraAdd
			end
		end
	end		

end


local timeElapsed = 0
while true do --process buttons
	for n=1,#MultisList do
		ProcessMultis(MultisList[n],timeElapsed)
	end
	for n=1,#RebirthsList do
		ProcessRebirths(RebirthsList[n],timeElapsed)
	end
	for n=1,#PrestigesList do
		ProcessPrestiges(PrestigesList[n],timeElapsed)
	end
	for n=1,#UltrasList do
		ProcessUltras(UltrasList[n],timeElapsed)
	end

	timeElapsed = task.wait()
end

thanks! the script now works and buttons too

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.