#petulant windmill refuses to give me cash

1 messages · Page 1 of 1 (latest)

shadow pollen
#

uuh im pretty sure i may be really stupid and its like a 1 minute fix but i am quite inexperienced with coding and need a second set of eyes to help me out
so i have these windmill things that you can buy for your tycoon, when you buy them theyre just supposed to give you 1 cash every 0.2 seconds
they spin and they play sounds just fine, and when you load them in using saved data they do generate cash, but when you first buy them they give nothing ??
ive been rearranging and rewriting this code for way too much time and i just want to get it over with and i dont know why it refuses to work PLEASE HELP ME
i will answer questions and send whatever is asked of me

shadow pollen
#

the second while loop was my shoddy attempt at troubleshooting, i need to rewrite this

strange silo
#

print player and show me the result

#

like before you check if plr is nil

shadow pollen
#

hold

#

my studio crashed hold for longer please

#

are there any slurs that can be used against roblox studio

strange silo
#

idk 😭

junior gorge
#

hello

#

are you assigning the player value correctly?

#

as you buy the windmill, it IS assigned, right?

#

ah

shadow pollen
junior gorge
#

also, if the player value continues to be nil, the while loop will run forever and on potentially crashing things (i think they fixed this but its good to do this anyway)

strange silo
shadow pollen
#

i used code from the tycoon core script

junior gorge
#

please add a wait inside your while loop to avoid crashing

shadow pollen
#

nvm

strange silo
#

cause ur loop is running with no delay it crashes

shadow pollen
#

exhausted allowed execution time

#

oops

junior gorge
#

inside your first while loop

#

that means you arent assigning the player value correctly, probably

shadow pollen
#

okay joining game it starts off nil

#

expected

#

though it shouldnt be running so early

junior gorge
#

double check where you're assigning the player value, and add a wait inside the first while loop

shadow pollen
#

i added the wait

junior gorge
#

you could do
if player ~= nil then
--code
else
task.wait(1)
end

shadow pollen
#

upon claiming the tycoon it retrieved save data and the player data was correctly assigned to me

#

let me reset the tycoon

junior gorge
#

so it wont crash anymore

shadow pollen
#

upon reset it printed my info out again

#

hold

junior gorge
#

okeh

shadow pollen
#

if i buy it

strange silo
#
local player = values.OwnerValue.Value
if not player then
    player = values.OwnerValue:GetPropertyChangedSignal("Value"):Wait()
end

do something like this if it runs to early

shadow pollen
#

no cash increase

#

fuck

#

it finds the player correctly but

#

no increase in moneys

junior gorge
#

please send the code that runs when you buy the windmill and set the players value

strange silo
#

he just said the player is correct 🙏

junior gorge
#

what

#

for real??

shadow pollen
#

stupid infernal windmill

junior gorge
#

but it works when you load it from a save

#

no?

shadow pollen
shadow pollen
junior gorge
#

are there any errors in output?

#

and can you show me your current code

shadow pollen
#

local values = script.Parent.Parent.Parent.Values
local center = script.Parent.Build:FindFirstChild("Center")

local ambience = script.Parent:WaitForChild("WindmillAmbience")

ambience.Parent = center
ambience:Play()

while true do
task.wait()
local player = values.OwnerValue.Value
print(player)
if player ~= nil then
while true do
local WINDMILL_TIME = 0.15 + math.random() * 0.1
player.leaderstats.Electrons.Value += 1
task.wait(WINDMILL_TIME)
end
end
end

#

current

#

my droppers and furnace and everything work fine so i am very confused

junior gorge
#

when you print player, it's just fine?

shadow pollen
#

now when i loaded the tycoon it didnt even print player yet it still gives me cash ????

junior gorge
#

hm

shadow pollen
#

upon resetting it does print the player

junior gorge
#

where is this script, by the way?

shadow pollen
#

yet it only prints once

lavish starBOT
#

studio** You are now Level 4! **studio

junior gorge
#

oh it's in the windmill

shadow pollen
#

correct

junior gorge
#

gosh

shadow pollen
#

I JUST WANT IT TO CONSTANTLY ADD CASH TO THE TYCOON WITHOUT ANY PARTS BEING DROPPED

#

WHY DOES IT DO THIS

#

do i have to rewrite the entire thing

#

interestingly the windmill even manages to add cashonce or twice after resetting, so you just start off with 2 cash instead of 0

junior gorge
#

when does the value get set?

#

the player value

shadow pollen
#

when the player claims the tycoon door

#

or when the player resets the tycoon, where it sets the value for the cloned tycoon that replaces the original

junior gorge
#

when does it start working?

shadow pollen
#

when the windmills are bought, get saved to serverstorage and when the player reconnects and claims the tycoon again

junior gorge
#

and you set the player value all the same?

#

the electrons value exists by then, right?

#

it gets created when the player joins?

shadow pollen
#

electrons = cash in this case

#

electrons value gets created when the player joins as leaderstats is in serverscriptservice

junior gorge
#

local values = script.Parent.Parent.Parent.Values
local center = script.Parent.Build:FindFirstChild("Center")

local ambience = script.Parent:WaitForChild("WindmillAmbience")

ambience.Parent = center
ambience:Play()

while true do
task.wait()
local player = values.OwnerValue.Value
print(player)
if player ~= nil then
print('Ran!')
while true do
local success, error = pcall(function()
local WINDMILL_TIME = 0.15 + math.random() * 0.1
player.leaderstats.Electrons.Value += 1
end)
print(error)
task.wait(WINDMILL_TIME)
end
end
end

#

try ts

#

tell me what shows up in output

#

sorry for the ass formatting im on mobile 🙏

shadow pollen
#

thank you

#

let me see

strange silo
#

could we please wrap the while true do function inside a

task.spawn(function()

)

😭

shadow pollen
#

starting console

#

nil is the player value that hasnt been set

#

really not sure why the second error takes place but it doesnt cause issues so ill deal with it later

junior gorge
#

oh shit i have made an error 🙏

shadow pollen
junior gorge
#

its not that but uh

shadow pollen
#

electrons are going up a mile a minute and somethings getting printed as nil

junior gorge
#

yeahyeah

lavish starBOT
#

studio** You are now Level 9! **studio

junior gorge
#

my bad 🙏

shadow pollen
#

upon resetting, it does say "Ran!"

strange silo
#

WHY THE FUCK ARE WE NOT USING THE REGULAR CONSOLE LIKE EVERYTHING IS SO ASS HERE

junior gorge
#

local values = script.Parent.Parent.Parent.Values
local center = script.Parent.Build:FindFirstChild("Center")

local ambience = script.Parent:WaitForChild("WindmillAmbience")

ambience.Parent = center
ambience:Play()

local WINDMILL_TIME = .15

while true do
task.wait()
local player = values.OwnerValue.Value
print(player)
if player ~= nil then
print('Ran!')
while true do
local success, error = pcall(function()
local WINDMILL_TIME = 0.15 + math.random() * 0.1
player.leaderstats.Electrons.Value += 1
end)
print(success)
task.wait(WINDMILL_TIME)
end
end
end

shadow pollen
#

this was after resetting

#

no input from the windmills

junior gorge
shadow pollen
#

why is windmill time defined twice

junior gorge
#

oh FUCK

#

change the local WINDMILL_TIME inside the while loop to just

#

WINDMILL_TIME

#

🙏

strange silo
#

yall gotta calm the fuck down this aint going anywhere fr

junior gorge
#

is just not there apparently

shadow pollen
#

yet i heard it

junior gorge
#

💀

shadow pollen
#

unless it never stopped ???

#

i need to tamper

junior gorge
#

maybe it was parented late

#

I have no idea

#

does it fucking work 😭

#

instead of redefining the windmilltime I wanted to just update it

shadow pollen
#

ignore the buttons ill fix them in a second

#

this was loading save data

junior gorge
#

it seems to be successful??

shadow pollen
#

so far so good

#

now to reset and to try and buy new

junior gorge
#

you changed it to update windmill time right

shadow pollen
#

i currently just left windmill time to .15

#

okay it doesnt play any audio after resetting

#

now i will proceed to buy

junior gorge
#

LMAO

#

oh I thought it broke

shadow pollen
#

shit straight up does NOTHING after resetting

#

💔 💔 💔

strange silo
#

LastFlareZ

#

does anything work rn

shadow pollen
#

zyos

#

define

junior gorge
#

show output

strange silo
#
local values = script.Parent.Parent.Parent:FindFirstChild("Values")
local ownerValue = values:FindFirstChild("OwnerValue")

local center = script.Parent.Build:FindFirstChild("Center")
local ambience = script.Parent:FindFirstChild("WindmillAmbience")

if center and ambience then
    ambience.Parent = center
    ambience:Play()
else
    print("abience or center not found")
end

local running = nil

local function startGenerating(player)
    if not player then print("player not found") return end

    running = task.spawn(function()
        print("started while loop")
        while ownerValue.Value == player do
            local leaderstats = player:FindFirstChild("leaderstats")
            local electrons = leaderstats and leaderstats:FindFirstChild("Electrons")
            if not electrons then print("electrons not found") break end

            electrons.Value += 1
            task.wait(0.15 + math.random() * 0.1)
        end
    end)
end

if ownerValue.Value then
    print("player is currently assigned")
    startGenerating(ownerValue.Value)
end

ownerValue:GetPropertyChangedSignal("Value"):Connect(function()
    running = nil
    if ownerValue.Value then
        print("player is currently assigned")
        startGenerating(ownerValue.Value)
    end
end)
junior gorge
#

🙏

strange silo
#

use this

#

and show me the console

junior gorge
#

gogo

shadow pollen
#

ai caramba what is that

#

okay

#

okay good no ugly nil player checking when i start

strange silo
#
task.spawn(function()
)

is just there that you can do stuff in the script below and the while true loop runs next to the script

strange silo
shadow pollen
#

success ???????

#

electron count is rising

junior gorge
#

peak

strange silo
#

does everything work?

junior gorge
#

i have no idea what the error was LMAO

#

cya

shadow pollen
#

okay so

lavish starBOT
#

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

shadow pollen
#

i reset my tycoon

#

the red stuff appeared when it set my player value

#

second one is when i bought it

#

except

#

i could hear the ambience and im pretty sure it was parented to center????

#

very strange

#

now i looked back and it was increasing

#

i am so confused

#

THE CODE WORKS

#

THANK YOU

strange silo
#

np

shadow pollen
#

now how do i clean it up so theres none of these strange prints

strange silo
#

lemme explain the task.spawn thing again incase you wanna edit the script

this is a while true loop with task.spawn

task.spawn(function()
  while true do
    task.wait()
  end
)

print("i will instantly run")

this is a while true loop with no task.spawn

while true do
  task.wait()
end

print("i will never run")
shadow pollen
#

curious

strange silo
#

idk its more of an advanced thing but its pretty useful

shadow pollen
#

i will research this more

#

thank you

#

this was horrific to deal with but i am at peace now

flint mirage
#

jeez, what a mess

shadow pollen
#

rat poison

flint mirage
shadow pollen
#

i am breaking those scripts to fit my image

#

i came in with zero coding knowledge

#

i am constructing some seriously freaky yet functional shit now

strange silo
#

scripting your own tycoon framework aint even that hard i think you could learn it in a week or two

shadow pollen
#

likely

flint mirage
shadow pollen
#

flourish my constructs

flint mirage
shadow pollen
shadow pollen
#

i do get issues frequently but usually its not as severe as this and i can fix them with little issue

flint mirage
shadow pollen
#

it seems fine for now but i might need to do a code efficiency consult later just to make sure everythings going dashing

strange silo
shadow pollen
#

political

flint mirage
#

and if there's some particular thing not working, trace it from start to end, prove each step.

#

just for future salute

shadow pollen
#

i think ill have to do a bit of debugging for these creatures

flint mirage
strange silo
#

fuck pathfinding 😭

flint mirage
strange silo
shadow pollen
#

for now the zombies are partly stolen code but with damage and flinch and attack animations and sounds and other shit added on

#

i need to research how to turn it into more of 'my' code

strange silo
shadow pollen
#

i temporarily removed the thing in the code that sets the idle and it did let the whole walk animation play out, just looked jank because of the idle not playing when its actually required

flint mirage
strange silo
flint mirage
strange silo
#

the docs are organzised so ass

flint mirage
shadow pollen
#

noted

flint mirage
#

like for every walkanimtrack:Play(), put a print next to it so you know the code is running

#

and if its running when it shouldn't be well you've just found your problem 👍

#

prints really are that powerful.

#

point is it may look like high level scripters magically know how to write code perfectly the first time but that's not true, it's just a lot of practice. trial and error, and a lot of it, is normal 👍

strange silo
#

like i said hes a poet

shadow pollen
#

good

#

that really is most strange

#

the "running" is it playing its walk animation

#

im really not sure why it does so

#

it looks really ugly