Regen code not working

  1. What do you want to achieve? Keep it simple and clear!

So I have a regen script that if the player has the needed amount of money, it spawns the item, and then you can use it, but now for no reason it refuses to work

  1. What is the issue? Include screenshots / videos if possible!
    Wont respawn the mode like it used to

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    tried reverting to an old version, but same thing, don’t know what happened

info under

script.IsCooldown.Value = false
backup = game.ReplicatedStorage.trains.paid.Combine.CombineTrainF

script.Parent.ClickDetector.mouseClick:connect(function(plr)
	local cost = script.Parent.Cost.Value
	if cost <=0 then cost = 5 end
	local balance = plr.leaderstats.Credits.Value
	if script.IsCooldown.Value == false then
	if plr.leaderstats.Credits.Value >= cost then		
			script.IsCooldown.Value = true
		plr.leaderstats.Credits.Value = balance - cost
		local clone = backup:clone()
			clone.Parent = workspace.game.PlayerTrains
		clone:MakeJoints()
			wait(5)
			script.IsCooldown.Value = false
	end	
end
end)








--local clone = backup:clone()
--clone.Parent = game.Workspace
--clone:MakeJoints()

thing

2 Likes
script.IsCooldown.Value = false
local backup = game.ReplicatedStorage.trains.paid.Combine.CombineTrainF

script.Parent.ClickDetector.MouseClick:connect(function(plr)
	local cost = script.Parent.Cost
	if cost.Value <=0 then cost.Value = 5 end
	local balance = plr.leaderstats.Credits
	if script.IsCooldown.Value == false then
	if plr.leaderstats.Credits.Value >= cost.Value then		
			script.IsCooldown.Value = true
		plr.leaderstats.Credits.Value = plr.leaderstats.Credits.Value - cost.Value
		local clone = backup:clone()
			clone.Parent = workspace.game.PlayerTrains
		clone:MakeJoints()
			wait(5)
			script.IsCooldown.Value = false
	end	
end
end)

This may work, I believe it was just a few simple Grammar errors

It’s MouseClick, not mouseClick.

Also, you should check for the debounce first as then the script doesn’t need to run unnecessary code.

local Debounce = false

if Debounce then
   return
end
Debounce = true
--
Debounce = false

You can add a player debounce instead of a global debounce, meaning only the player that triggered the clickdetector would get the debounce, not everyone else as well.

global is better so they dont get objects spawning inside each other

You’d have to check if the object touching it is a player.
This is better if OP decides to implement it as it might be sligthly annoying if every player has to wait because another player triggered the debounce.


there will be 4 total spawn areas

as i am seeing in your script you are using lots of debounces
try this:

script.Parent.ClickDetector.MouseClick:connect(function(plr)
	local cost = script.Parent.Cost.Value --- set your cost num
	if cost.Value <=0  then return end
	local balance = plr.leaderstats.Credits
	
   
	if plr.leaderstats.Credits.Value >= cost then	
      if script.IsCooldown.Value == false then	
			 script.IsCooldown.Value = true
		plr.leaderstats.Credits.Value = plr.leaderstats.Credits.Value - cost
		local clone = backup:clone()
			clone.Parent = workspace.game.PlayerTrains
		clone:MakeJoints()
			wait(5)
			script.IsCooldown.Value = false
	     end
   end
end)

error

 Workspace.Regen-Normal.Script:3: attempt to index number with 'Value'

try removing the value in the variable

but the value directs it to the number inside of the value object

Basically cost is already a value so when you do cost.Value it will return nil because you can not get the value of a value of something. Remove the value like @MrchipsMa said and it should work