Hello everyone, I have been trying to make a bit of a tycoon-ish type of game and have been messing around adding some important code to my buttons for awhile now to get the ball rolling and I have been stress testing on whether or not I can get a certain script to warn me whenever I have invalid/conflicting configuration settings (in this case, I’m trying to get the script to warn me that there is no existent tycoon button with the name number identity of 0 that can be cloned into the workspace) to prevent troubling script breaks. Problem is, is I still get errors despite putting in the instance check here:
(Full Code Overview)
local debounce = 0
local price = script.Parent.Parent.Configuration.Price.Value
local config = script.Parent.Parent.Configuration
local buytargetname = script.Parent.Parent.Configuration.ObjectName.Value
local checkpoint = script.Parent.Parent.Configuration.Checkpoint.Value
local cmin = config.ButtonNumMin.Value
local cmax = config.ButtonNumMax.Value
local text1 = script.Parent.Parent.TextGui.Text1Sur.Text
local text2 = script.Parent.Parent.TextGui.Text2Sur.Text
text1.Text = ("Buy "..buytargetname.." for "..price)
text2.Text = ("Buy "..buytargetname.." for "..price)
function onTouched(hit)
if debounce == 0
then
debounce = 1
local check = hit.Parent:FindFirstChild("Humanoid")
if check ~= nil then
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
local stats = user:findFirstChild("leaderstats")
if config.Multiplier.Value == true then
if stats ~= nil then
local cash = stats:findFirstChild("Currency")
if cash.Value > price then
cash.Value = cash.Value - price
game:GetService("ServerScriptService").ServerConfig.CurrencyMultiplier.Value = game:GetService("ServerScriptService").ServerConfig.CurrencyMultiplier.Value*2
print("Server Multiplier set to "..game:GetService("ServerScriptService").ServerConfig.CurrencyMultiplier.Value)
if checkpoint == true then
for i = cmin,cmax do
if game:GetService("ReplicatedStorage").TycoonButtons["TycoonButton"..i] ~= nil then
local buttonclone = game:GetService("ReplicatedStorage").TycoonButtons["TycoonButton"..i]:clone()
buttonclone.Parent = workspace
else
warn("TycoonButton"..i" does not exist! Checkpoint invalid!")
end
end
script.Parent.Parent:Destroy()
end
end
end
else
if stats ~= nil then
local cash = stats:findFirstChild("Currency")
if cash.Value > price then
cash.Value = cash.Value - price
local clonedobj = game:GetService("ReplicatedStorage").TycoonObjects[buytargetname]:Clone()
clonedobj.Parent = workspace
if checkpoint == true then
for i = cmin,cmax do
if game:GetService("ReplicatedStorage").TycoonButtons["TycoonButton"..i] ~= nil then
local buttonclone = game:GetService("ReplicatedStorage").TycoonButtons["TycoonButton"..i]:clone()
buttonclone.Parent = workspace
else
warn("TycoonButton"..i" does not exist! Checkpoint button spawning invalid!")
end
end
end
script.Parent.Parent:Destroy()
end
end
end
end
end
debounce = 0
end
script.Parent.Touched:connect(onTouched)
Don’t really know how to fix this and I feel like I’m missing something super obvious here like a stray end being in the wrong line somehow (I checked even that and couldn’t find anything) but regardless I could use some help here. If you know anything, please do tell. I would appreciate it!