i am using a packaged script for many tycoons. it is supposed to act independently for each tycoon. i have 4 different kinds of tycoons, their main difference is that they are referencing different structures. earth, venus, mars, ceres. they have different buttons and objects.
so the issue is, when i spawn in, only ONE of them activates, and this only working tycoon is random. that means when player chooses a tycoon to put player in, some random tycoon nearby gets activated instead. assistant says it maybe happening in case many scripts reference one instance, but HOW can this be a problem???
script:
local tycoon = script.Parent
local ownerValue = tycoon.owner
local tycoonButtonsContainer = tycoon.buttonsContainer
local tycoonObjectsContainer = tycoon.objectsContainer
local buildSound = script.buildsound
local serverStorage = game:GetService('ServerStorage')
local tycoonSaveName: 'Ρ Π·Π°Π³Π». Π±ΡΠΊΠ²Ρ' = tycoon.planet.Value --ΠΏΠΎ ΡΡΠΎΠΌΡ Π½Π°Π·Π²Π°Π½ΠΈΡ Π±ΡΠ΄Π΅Ρ Π½Π°Ρ
ΠΎΠ΄ΠΈΡΡΡΡ ΠΏΠ°ΠΏΠΊΠ° Π΄Π»Ρ ΡΠΎΡ
ΡΠ°Π½Π΅Π½ΠΈΠΉ
local plot = tycoon.plot
local referenceTycoonModel = tycoon.referenceTycoonModel.Value --ΡΠΊΠ°Π·Π°ΡΡ ΠΌΠΎΠ΄Π΅Π»Ρ-ΡΠ΅ΡΠ΅ΡΠ΅Π½Ρ ΡΠ°ΠΉΠΊΡΠ½Π° Π² ΡΠ΅ΡΠ²Π΅ΡΠ½ΠΎΠΌ Ρ
ΡΠ°Π½ΠΈΠ»ΠΈΡΠ΅
local claimSpotButton = referenceTycoonModel['CLAIM SPOT']:Clone()
claimSpotButton.CFrame = plot.CFrame:ToWorldSpace(referenceTycoonModel.plot.CFrame:ToObjectSpace(claimSpotButton.CFrame))
claimSpotButton.Parent = tycoon
local buttonOriginTransparency = claimSpotButton.Transparency
if not referenceTycoonModel then warn('TYCOON REFERENCE NOT ASSIGNED') return end
local afkIncomequantities, afkIncomeCfg = tycoon.incomeStats, tycoon.incomeParams
local serverBuild = tycoon.serverBuild
task.wait(.5)
function clearObjects(): "ΠΈΠ·Π±Π°Π²ΠΈΡΡΡΡ ΠΎΡ ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ²"
for index, object in pairs(tycoonObjectsContainer:GetChildren()) do
object:Destroy()
end
end
function checkUp(object, taebl): "ΠΏΠΎΠ΄Π³ΠΎΡΠΎΠ²ΠΈΡΡ ΠΎΠ±ΡΠ΅ΠΊΡ ΠΊ Π°Π½ΠΈΠΌΠ°ΡΠΈΠΈ"
for i, part in pairs(object:GetChildren()) do
if part.ClassName == 'Part' or part.ClassName == 'UnionOperation' or part.ClassName == 'MeshPart' then
table.insert(taebl, part)
elseif part.ClassName == 'Model' then
checkUp(part, taebl)
end
end
end
function addIncome(button): 'Π΄ΠΎΠ±Π°Π²ΠΈΡΡ 1 ΠΊ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²Ρ Π°ΡΠΊ ΡΠ°ΡΠΌΠΈΠ»ΠΎΠΊ, Π΅ΡΠ»ΠΈ ΡΠ°ΠΊΠ°Ρ Π±ΡΠ»Π° ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½Π°'
local object = tycoonObjectsContainer:FindFirstChild(button.Name)
--iterate through all build classes in afk income folder
for index, objectClass in pairs(afkIncomequantities) do
if object:HasTag(objectClass.Name) then
objectClass.Value += 1
end
end
end
function animation(object, button): "Π°Π½ΠΈΠΌΠ°ΡΠΈΡ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Π΄Π΅ΡΠ°Π»ΡΠΊΠΈ ΠΎΠ±ΡΠ΅ΠΊΡΠ°"
local soundClone = script.animSound:Clone()
soundClone.Parent = button
soundClone:Play()
local parts = {}
checkUp(object, parts)
local transparencyTable = {}
local collisionTable = {}
for t,part in pairs(parts) do
table.insert(transparencyTable, part.Transparency)
table.insert(collisionTable, part.CanCollide)
end
for i,part in pairs(parts) do
part.Transparency = 1
part.CanCollide = false
end
for i,part in pairs(parts) do
local relativeCFrame = referenceTycoonModel.plot.CFrame:ToObjectSpace(part.CFrame)
local targetCFrame = plot.CFrame:ToWorldSpace(relativeCFrame)
local duration = 3 / #parts
local tween = game.TweenService:Create(part, TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Transparency = transparencyTable[i], CFrame = targetCFrame})
part.CFrame = ownerValue.Value.Character.Head.CFrame
part.CFrame *= CFrame.Angles(math.random(-180,180), math.random(-180,180), math.random(-180,180))
tween:Play()
tween.Completed:Wait()
part.CanCollide = collisionTable[i]
task.wait(duration * 0.5)
end
soundClone:Destroy()
end
function switchButton(button, enabled): "ΠΎΡΠΎΠ±ΡΠ°Π·ΠΈΡΡ\ΡΠΊΡΡΡΡ ΠΊΠ½ΠΎΠΏΠΊΡ"
if enabled == true then
button.Transparency = buttonOriginTransparency
else
button.Transparency = 1
end
button.CanTouch = enabled
button.ButtonBillboard.Enabled = enabled
button.CanCollide = enabled
end
function updateButtons()
--ΠΏΠ΅ΡΠ΅Π±ΡΠ°ΡΡ ΠΊΠ½ΠΎΠΏΠΊΠΈ
for i, button in pairs(tycoonButtonsContainer:GetChildren()) do
local associatedObject = tycoonObjectsContainer:FindFirstChild(button.Name)
local previousObject
local parentValue = button.par.Value
if parentValue then
previousObject = tycoonObjectsContainer:FindFirstChild(parentValue.Name)
end
if associatedObject then --if this button was bought before the check
switchButton(button, false)
else --if this button was not bought before the check
if previousObject or button.par.Value == nil then --if previous object bought or there is not supposed to be one
switchButton(button, true)
else
switchButton(button, false)
end
end
end
end
--ΠΏΠΎΠ΄Π³ΠΎΡΠΎΠ²ΠΈΡΡ ΠΊΠ½ΠΎΠΏΠΊΠΈ ΠΊ ΡΠ°Π±ΠΎΡΠ΅ ΠΏΠΎΡΠ»Π΅ Π·Π°ΠΏΡΡΠΊΠ° ΡΠ΅ΡΠ²Π΅ΡΠ°
for i, button in pairs(referenceTycoonModel.buttonsContainer:GetChildren()) do
local relativeCFrame = referenceTycoonModel.plot.CFrame:ToObjectSpace(button.CFrame)
button.CFrame = plot.CFrame:ToWorldSpace(relativeCFrame)
print(plot.Parent.Name, plot.CFrame)
local buttonType = 'money'
local currencyIcon = 'π΅'
if button:FindFirstChild('buttonGemModificator') then currencyIcon = 'π' buttonType = 'gems' end
if button:FindFirstChild('buttonMatterModificator') then currencyIcon = 'π' buttonType = 'matter' end
button.ButtonBillboard.TextLabel.Text = button.Name..' for '..button.cost.Value..currencyIcon
button.ButtonBillboard.Enabled = true
button.Parent = tycoonButtonsContainer
button.Touched:Connect(function(touch)
local thisButton = button
local player = game.Players:GetPlayerFromCharacter(touch.Parent)
if ownerValue.Value ~= nil or serverBuild.Value == true then
if player.Name == ownerValue.Value.Name or serverBuild == true then
local leaderstats = player:WaitForChild('leaderstats')
local playerMoney = leaderstats:WaitForChild('money')
local playerGems = leaderstats:WaitForChild('gems')
local playerDarkMatter = leaderstats:WaitForChild('matter')
local usedCurrency = playerMoney
if buttonType == 'gems' then
usedCurrency = playerGems
elseif buttonType == 'matter' then
usedCurrency = playerDarkMatter
end
local buttonCost = thisButton.cost.Value
if usedCurrency.Value >= buttonCost and not tycoonObjectsContainer:FindFirstChild(thisButton.Name) then
switchButton(thisButton, false)
usedCurrency.Value -= buttonCost
local object = referenceTycoonModel.objectsContainer:FindFirstChild(thisButton.Name)
local objectClone = object:Clone()
objectClone.Parent = tycoonObjectsContainer
--animation where clone object being constructed part by part
task.spawn(animation, objectClone, thisButton)
updateButtons()
local sndClone = buildSound:Clone()
sndClone.Parent = thisButton
sndClone:Play()
task.wait(.6)
sndClone:Destroy()
if serverBuild == false then
local documentOfPurchasing = Instance.new('Configuration')
documentOfPurchasing.Parent = player[tycoonSaveName]
documentOfPurchasing.Name = thisButton.Name
end
end
end
end
end)
end
task.wait()
updateButtons()
ownerValue.Changed:Connect(function(plr)
if not plr then
clearObjects()
updateButtons()
switchButton(claimSpotButton, true)
else
switchButton(claimSpotButton, false)
--Π·Π°Π³ΡΡΠ·ΠΊΠ° ΡΠΎΡ
ΡΠ°Π½ΠΈΠ²ΡΠΈΡ
ΡΡ ΠΏΠΎΠΊΡΠΏΠΎΠΊ
local savedObjects = plr[tycoonSaveName]:GetChildren()
if savedObjects ~= nil then
for i,v in pairs(savedObjects) do
local clone = referenceTycoonModel.objectsContainer:FindFirstChild(v.Name):Clone()
clone.Parent = tycoonObjectsContainer
task.wait()
end
end
updateButtons()
end
end)
claimSpotButton.ButtonBillboard.TextLabel.Text = 'Deploy a colony here for '..claimSpotButton.cost.Value .. "$"
if serverBuild == true then switchButton(claimSpotButton, false) end
claimSpotButton.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr.leaderstats.money.Value >= claimSpotButton.cost.Value then
plr.leaderstats.money.Value -= claimSpotButton.cost.Value
switchButton(claimSpotButton, false)
ownerValue.Value = plr
script.claimed:FireClient(plr, tycoon.Parent)
end
end
end)
Is the assistent right? even if it is, why would this happen anyways???