I'm having problems trying to get this script to work consistently. It is supposed to check that person touching it owns the tycoon and if so it will check if they have enough money to complete a purchase. If they have enough money it will increase the income (The value of which is stored in the 'IntValue' shown in the script) and then increase the cost of the upgrade for the next purchase. The main issues seem to be that 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)

9 comments
Hope my answer helps you out! For any additional questions post them in the comments under my answer.
I edited my answer at the bottom to hopefully assist you.
If you do use a LocalScript to activate the gui you will need to keep it somewhere other than serverstorage. ServerStorage cannot be accessed by the client or a LocalScript.
If you do use a LocalScript to activate the gui you will need to keep it somewhere other than serverstorage. ServerStorage cannot be accessed by the client or a LocalScript.
Remember that I said that LocalScripts cannot access serverstorage. You will have to store the remote event in something like replicated storage which the client/local script can access
If I use a Localscript inside the button the user must touch, the button won't work at all.
I have also moved the MessageGui to ReplicatedStorage
could you post the script either in an edit to this question or a new question?
If I helped you out please accept my answer.