I'm having problems trying to get this script to work consistently. Sometimes it will take a long time before executing or it will just break and I have no idea why.

Does anyone know what a potential problem is and how I can go about fixing it??? Thank you

local tycoon = script.Parent.Parent.Parent
local owner = tycoon.Owner -- StringValue for the owner's name
local income = tycoon.Income -- IntValue where income is stored
local debounce = false
local cost = 100 -- Starting price
local costAdd = 115 -- Price increase each purchase
local incomeAdd = 35 -- Income increase each purchase
local times = 4 -- Number of upgrades possible
local timeNum = 0
local ServerStorage = game:GetService("ServerStorage")
local Gui = ServerStorage.MessageGui

script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)

if player ~= nil and debounce == false then

if player and not player.PlayerGui:FindFirstChild(Gui.Name) then
        Gui:Clone().Parent = player.PlayerGui

debounce = true
if owner.Value ~= player.Name then
player.PlayerGui.MessageGui.Message.Alert.Text = "You are not the owner of this tycoon!"

wait(3) -- Wait time to be touched again
player.PlayerGui.MessageGui:Destroy()
debounce = false
return end
if player.leaderstats.Money.Value < cost then
local mn = cost-player.leaderstats.Money.Value
player.PlayerGui.MessageGui.Message.Alert.Text = "Insufficient funds! You need $" ..mn.. " more!"

wait(3) -- Wait time to be touched again
player.PlayerGui.MessageGui:Destroy()
debounce = false
return end
player.leaderstats.Money.Value = player.leaderstats.Money.Value - cost
income.Value = income.Value + incomeAdd
cost = cost + costAdd
timeNum = timeNum + 1
player.PlayerGui.MessageGui.Message.Alert.Text = "Upgrade complete! Income is now $" ..income.Value.. "!"

script.Parent.Parent.Name = "Upgrade Owner's Income - $" ..cost
if timeNum == times then
for i = 0.4, 1, 0.01 do
wait()
script.Parent.Transparency = i
debounce = true
end
script.Parent.Parent:Destroy()
end
wait(3) -- Wait time to be touched again
player.PlayerGui.MessageGui:Destroy()
debounce = false
end
end
end)

1 comment

0

Title and description of this problem is way to broad. Plus, cluttered code doesn't help us understand what to look for. Be more specific.