#Why does it print when player joins?
22 messages · Page 1 of 1 (latest)
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
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:
-
Assuming you're ultimately changing the
Eggsvalue under the player, your script only checks the prefabEggsthat exists under it. This will lead you to look at the wrongIntValue/NumberValueinstance. -
Checking if
Eggs.Valueis <= 5 doesn't make sense for an additive goal. Assuming no eggs have been found, andEggs.Valuerepresents the number of found eggs, 0 eggs found passes the condition of being less than or equal to 5. You mean to check ifEggs.Valueis >= 5
so like >=5 instead of <=5?
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
For example, your function bound to Players.PlayerAdded runs when a player enters the game
The "Changed" event above will run when the "Value" property of your IntValue/NumberValue changes
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
so do not do <=5 ?
TL;DR: Your code will think the player has found all eggs when none have actually been found
right, but i try the >=5 and it does nothing if you cant tell im not an advance scripter thanks for trying to help
So did I do something to the >=5
Did you solve all the other problems I mentioned?
All problems must be solved in order for your code to work properly, and that's assuming the external code is also written correctly
** You are now Level 9! **