#Why does it print when player joins?

22 messages · Page 1 of 1 (latest)

queen kayakBOT
#

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

faint adder
#

because you're not doing it correctly

#

the if statement will immediately run when the script is created

#

you need to use the Eggs variable inside the PlayerAdded function, connect .Changed to Eggs, then check if the value <= 5

glacial sequoia
#

If statements do not state when something should happen. The question is asked once at the time when execution reaches the if statement. Since your script executes when the server boots, you have virtually no time at all to change Eggs.Value to a value <= 5

#

To run code when something happens, you use events. Alternatively, though less optimal, you can repeatedly ask the question in a loop

#
eggs.Changed:Connect(function(newValue)
    -- ...
end)
#

There are two more issues I see with your script:

  1. Assuming you're ultimately changing the Eggs value under the player, your script only checks the prefab Eggs that exists under it. This will lead you to look at the wrong IntValue/NumberValue instance.

  2. Checking if Eggs.Value is <= 5 doesn't make sense for an additive goal. Assuming no eggs have been found, and Eggs.Value represents the number of found eggs, 0 eggs found passes the condition of being less than or equal to 5. You mean to check if Eggs.Value is >= 5

sullen geyser
#

so like >=5 instead of <=5?

glacial sequoia
# sullen geyser im lost bro

Your code reads "is Eggs.Value <= 5", not "when Eggs.Value <= 5". Because you're asking a question at a single moment in time, the code within the if statement will not run if the question is not answered correctly at that time; if the answer becomes correct in the future, the code will still fail to run

glacial sequoia
#

For example, your function bound to Players.PlayerAdded runs when a player enters the game

glacial sequoia
#

This helps you stay up-to-date with the state of that property, and you can ask whether or not the value is >= 5 at the time it updates

sullen geyser
#

so do not do <=5 ?

glacial sequoia
#

TL;DR: Your code will think the player has found all eggs when none have actually been found

sullen geyser
#

right, but i try the >=5 and it does nothing if you cant tell im not an advance scripter thanks for trying to help

sullen geyser
glacial sequoia
#

All problems must be solved in order for your code to work properly, and that's assuming the external code is also written correctly