#tycoon help please

103 messages · Page 1 of 1 (latest)

nova kindle
#

i’m back again, my cash collector doesn’t seem to be working. i’m uploading a video of the problem rn, but here’s my script

wind lake
#

Jeez man... Why dont you just hire us for free to make a game for you?

nova kindle
#

👍🏾👍🏾

#

once i get the hang of it i’ll make myself scarce

nova kindle
#

first i find out about coroutines now this🤦🏾‍♀️

wind lake
nova kindle
#

yes i know

pallid comet
nova kindle
wind lake
pallid comet
nova kindle
#

here it is again

nova kindle
placid ridge
#

No

#

Send it in text

pallid comet
#

thats what i was about to say

elfin girder
#

Sup wassup again

placid ridge
#

I don’t want to see your screen glare all over the script mate

nova kindle
#

bruh i can’t get discord on this intel celeron ass pc😔
i can try but give me a few minutes

#

i’m surprised roblox studio works on this

wind lake
placid ridge
#

almost any modern day laptop should be able to run discord

wind lake
#

Guys, lets all make a game for this guy so he doesnt have to create a post every hour

placid ridge
#

and I see windows 10, windows 10 machines should easily be able to do so

nova kindle
placid ridge
#

done within a hour

placid ridge
wind lake
nova kindle
#

ykw

placid ridge
#

I had a low end laptop that was also made roughly 6 years ago, it could easily run discord and it only had 4 gbs of ram

nova kindle
#

since y’all planning to do all this

placid ridge
#

I pentium I think

nova kindle
#

there

wind lake
nova kindle
#

the actual code is in workspace>tycoons>tycoon>scripts>core

nova kindle
#

i wish my mess was pentium

placid ridge
#

I'm glad I don't need a pentium anymore

placid ridge
#

1 test and it already shows a stack end

#

did you ever test this script?

wind lake
#

errors = good script

nova kindle
#

multiple times but idk what a stack end is

#

thhat wasn’t in the roblox studio tutorials i’ve seen

#

they always ignore it

placid ridge
#

what the fuck

#

a stack end means the script will stop working

#

once a script comes across a line while running it can't execute then it will stack end, meaning it will stop running the script and return an error

#

an example of this:

print("Hello world")
syntax error which will clearly stack end the script
print("Hello world")

it will print once, then stack end on line 2

nova kindle
#

ohh wait so

#
11:51:00.264  Stack Begin  -  Studio
  11:51:00.264  Script 'Workspace.Tycoons.Tycoon.Scripts.Core', Line 169  -  Studio - Core:169
  11:51:00.265  Stack End  -  Studio
#

this core script stopped working at like 169?

wind lake
#

yea

#

There is the error

nova kindle
#

man wtf

#

wait i know why

#

some of the object values i added disappear when i test the game

winged hinge
#

The Issue is located in the "playSound" function remove the "wait(1)" and the issue will be fixed

#

This is caused because the sound finished playing before the Ended:Wait() call

placid ridge
#

just noticed that in a test as well, quite sure those 2 models get destroyed by a script

winged hinge
#

So it is in a infinite loop of waiting

placid ridge
winged hinge
#

Change it to FindFirstChild

#

Is there a reason to use WaitForChild()?

placid ridge
#

I've just read a tad more script and I notice that the script removes those items from existence

nova kindle
#

browser version of discord + roblox studio was too much for it 😔

winged hinge
#

I tested it and it was the issue with the cash collector

#

tell me if it works for you

nova kindle
lusty cragBOT
#

studio** You are now Level 5! **studio

placid ridge
#

like this was caused by both a sound being shorter than a wait (so it ended before the script started waiting for it to end

#

oh

#

I guess discord doesn't like that plugin

#
local tycoon = script.Parent.Parent

local mainItems = tycoon:FindFirstChild("MainItems")
local values = tycoon:FindFirstChild("Values")

local buttons = tycoon:FindFirstChild("Buttons")
local purchasedItems = tycoon:FindFirstChild("PurchasedItems")
local audio = tycoon:FindFirstChild("Audio")

local debounce = false

local objects = {}

local tweenService = game:GetService("TweenService")

local random = Random.new()

local BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT = 2
local BUILDING_ANIMATION_PART_DELAY = .03

function hasProperty(instance,property)
    assert(typeof(instance) == "Instance")
    assert(typeof(property) == "string")
    
    local hasProperty = false
    
    pcall(function()
        local v = instance[property]
        hasProperty = true -- This line only runs if the previous line didn't error
    end)
    
    return hasProperty
end

function instanceListToPropertyDict(instances, propertyList)
    assert(typeof(instances) == "table")
    assert(typeof(propertyList) == "table")
    
    -- [[given a list of instances and a list of properties, construct a disctionary like so:
--    dict = {
    --    [instance1] = {property1 = instance1.property1, property2 = instance1.property2, ...},
    --    [instance2] = {property1 = instance2.property1, property2 = instance2.property2, ...},
    --    ...
    --}]]
    local dict = {}
    for _, instance in ipairs(instances) do
        local dictEntry = {}
        
        for _, property in pairs(propertyList) do
            assert(hasProperty(instance,property), string.format(
                [[Instance '%s' (a %s) doesn't have property '%s'.]],
                tostring(instance), instance.ClassName, property)
            )
            dictEntry[property] = instance[property]
        end
        
        dict[instance] = dictEntry
    end
    
    return dict
end
#
function getDescendantsWhichAre(ancestor,className)
    assert(typeof(ancestor) == "Instance")
    assert(typeof(className) == "string")
    
    --[[returns all descendants of ancestor which are of class className or a class that inherits from className]]
    local descendants = {}
    
    for _, descendant in pairs(ancestor:GetDescendants()) do
        if descendant:IsA(className) then
            table.insert(descendants, descendant)
        end
    end
    
    return descendants
end

function animateBuildingIn(buildingModel,tweenInfo)
    assert(typeof(buildingModel) == "Instance" and buildingModel.ClassName == "Model", string.format(
        "Invalid argument #1 to 'animateBuildingIn' (Model expected, got %s)",
        typeof(buildingModel) == "Instance" and buildingModel.ClassName or typeof(buildingModel)
        ))
    assert(typeof(tweenInfo) == "TweenInfo",string.format(
        "Invalid argument #1 to 'animateBuildingIn' (TweenInfo expected, got %s)",
        typeof(tweenInfo)
        ))
    --Collect BaseParts and original properties
    local parts = getDescendantsWhichAre(buildingModel, "BasePart")
    local originalProperties = instanceListToPropertyDict(parts, {"Transparency", "CFrame", "Color", "Size"})
    
    --make parts invisible and randomly move them
    for _, part in pairs(parts) do
        part.Transparency = 1
        part.Color = Color3.fromRGB(255,255,255)
        part.Size = Vector3.new()
        
        local positionOffset = Vector3.new(random:NextNumber(-1,1),random:NextNumber(-.25,1.75),random:NextNumber(-1,1)) * BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT
        local rotationOffset = CFrame.Angles(random:NextNumber(-math.pi, math.pi),random:NextNumber(-math.pi, math.pi),random:NextNumber(-math.pi, math.pi))
        part.CFrame *= CFrame.new(positionOffset) * rotationOffset
    end
    
    --tween them back to their original state, one at a time```
#

    local lastTween --Return this so the caller can do animateBuilding(...):Wait() to wait for the animation to complete
    
    for _, part in pairs(parts) do
        local tween = tweenService:Create(part,tweenInfo,originalProperties[part])
        lastTween = tween
        
        tween.Completed:Connect(function(playbackState)
            --sometimes tweens stop before reaching their goal properly.
            -- make sure each Part is *exactly* how it was before.
            part.Transparency = originalProperties[part].Transparency
            part.CFrame = originalProperties[part].CFrame
        end)
        
        tween:Play()
        
        wait(BUILDING_ANIMATION_PART_DELAY)
    end
    
    return lastTween.Completed
end

mainItems.OwnerDoor.Door.Touched:Connect(function(hit)
    if values.OwnerValue.Value == nil then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            if player:FindFirstChild("hasTycoon").Value == false then
                values.OwnerValue.Value = player
                mainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tostring(values.OwnerValue.Value).."'s Tycoon"
            end
        end
    end
end)

function playSound(object,soundID)
    if object:FindFirstChild("Sound") then
        return
    else
        local sound = Instance.new("Sound",object)
        sound.SoundId = soundID
        sound:Play()
        sound.Ended:Wait()
        sound:Destroy()
    end
end

if buttons then
    for i,v in pairs(buttons:GetChildren()) do
        spawn(function()
            if v:FindFirstChild("Button") then
                
                local newObject = purchasedItems:FindFirstChild(v.Object.Value)
                if newObject ~= nil then
                    objects[newObject.Name] = newObject:Clone()
                    newObject:Destroy()
                    
                else
                    v:Destroy()```
#

                end
                
                if v:FindFirstChild("Dependency") then
                    v.Button.Transparency = 1
                    v.Button.CanCollide = false
                    v.Button.BillboardGui.Enabled = false
                    coroutine.resume(coroutine.create(function()
                        if purchasedItems:FindFirstChild(v.Dependency.Value) then
                            v.Button.Transparency = 0
                            v.Button.CanCollide = true
                            v.Button.BillboardGui.Enabled = true
                        end
                    end))
                end
                
                v.Button.Touched:Connect(function(hit)
                    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
                    if player then
                        if values.OwnerValue.Value == player then
                            if v.Button.CanCollide == true then
                                if player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
                                    player.leaderstats.Cash.Value -= v.Price.Value
                                    objects[v.Object.Value].Parent = purchasedItems
                                    playSound(v,audio.buttonSound.SoundId)
                                    v:Destroy()
                                end
                            end
                        end
                    end
                end)
            end
            tycoon.PurchasedItems.ChildAdded:Connect(function(add)
                animateBuildingIn(purchasedItems:FindFirstChild(v.Object.Value),TweenInfo.new(1,Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)):Wait()
            end)
        end)
    end
end

mainItems.CashCollector.Button.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil then```
#

        if values.OwnerValue.Value == player then
            if player.Character.Humanoid.Health > 0 then
                if debounce == false then
                    debounce = true
                    mainItems.CashCollector.Button.BrickColor = BrickColor.new("Really red")
                    player.leaderstats.Cash.Value += values.MoneyValue.Value
                    values.MoneyValue.Value = 0
                    playSound(mainItems.CashCollector,audio.moneySound.SoundId)
                    task.wait(1)        --cooldown before cash can be collected once again
                    mainItems.CashCollector.Button.BrickColor = BrickColor.new("Lime green")
                    debounce = false
                end
            end
        end
    end
end)

--purchasedItems.KillDoor.Build.killDoorHitBox.Touched:Connect(function(hit)
--    print('bruh')
--    local humanoid = hit.Parent:FindFirstChild("Humanoid")
--    if humanoid then
--        print(humanoid.Name)
--    end
--end)```
#

there's your fixed script @nova kindle

#

took me a tad because I had some debugging prints as I wanted to make sure some other parts of the functions where working

patent oar
#

I ain't reading allat

nova kindle
#

i def will

nova kindle
placid ridge
# nova kindle i def will

all this changes over your old script is remove the wait in the PlaySound function, then change out the error line's WFC for a FFC, and add a small note around the end

wind lake
#

Cmon guys... Just let the guy do his own game, are you really gonna make the entire game wtf?

placid ridge
#

we agreed that I get 140% of the revenue

elfin girder
#

Hahaha

nova kindle
#

the killdoor

placid ridge
#

Let me smoke 1 more cig and I’ll do some testing