Old: It works at the very start of a different script and this script works perfectly without it. I’ve tried tons of different ways of writing it but it never works. The bool (CheckIfPlayerIsInArea2) is definitely changing to true but it still doesn’t proceed with the rest of the script.
getRandomPlayer()
CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"Let's split up to cover more ground.")
wait(5)
repeat wait(0.05) until game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2.Value == true
CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"it worked")
this is the entire output:
true - Server - check if player in area:5
00:30:28.533 CheckIfPlayerIsInArea is not a valid member of Model "Workspace.tutorialMonster" - Server - check if player in area:2
00:30:28.534 Stack Begin - Studio
00:30:28.534 Script 'Workspace.Area.check if player in area', Line 2 - Studio - check if player in area:2
00:30:28.534 Stack End - Studio
00:30:28.942 CheckIfPlayerIsInArea is not a valid member of Model "Workspace.tutorialMonster" - Server - check if player in area:2
00:30:28.942 Stack Begin - Studio
00:30:28.942 Script 'Workspace.Area.check if player in area', Line 2 - Studio - check if player in area:2
00:30:28.942 Stack End - Studio
00:30:33.541 Infinite yield possible on 'Workspace.tutorialMonster:WaitForChild("Humanoid")' - Studio
00:30:33.542 Stack Begin - Studio
00:30:33.542 Script 'Workspace.tutorialMonster.Health', Line 6 - Studio - Health:6
00:30:33.542 Stack End - Studio
The only thing I can think of is the tutorialMonster is somehow affecting this script.
Instead of
game.StarterPlayer.StarterCharacterScripts.CheckIfPlayerIsInArea2
do
game.Players.LocalPlayer.Character.CheckIfPlayerIsInArea2.Value == true
These two lines of code are essentially the same thing. If something exists, it should evaluate to true.
For example, I can do this code:
local player --equal to player
if player.Character then
--code
end
This code checks if the player exists by converting it to a true/false value. If the player exists, it’s true. If it’s not, it’s false (nil → boolean is false).
Because the first one only checks the starterplayer which will affect, not the player, but the starterplayer. That’s all it will do.
The one I said to change it to checks INSIDE the actual player.
I don’t see how that code would work because you can’t get the localplayer in a serverscript, and your player value is nil, so you’re basically doing if nil.Character == true which doesn’t make any sense.
To get a player in ServerScripts, I would either use the playerAdded event and then use the “player” parameter, or loop through the Players service and check if v == to someone’s username.
Oops! My bad. I thought you were trying to say to switch a boolean thing to an == operation.
I think the code is server sided, because they use FireAllClients.
OP:
There are two possible problems:
You use the instance before it exists. In this case, use WaitForChild before hand.
Your instance will never be there, and you’re looking in the wrong place. In this case, you’ll need to change your code to reference the correct object.
repeat wait() until shouldn’t be used for something like this, I get it seems simple but using wait() can really slow down your game.
If you need to detect a value change, use .Changed
Instead of:
repeat
wait()
until Value2.Value == true
Do:
local HasChanged = false
Value2.Changed:Connect(function(Property)
if Property == "Value" then
if Value2.Value == true and not HasChanged then
HasChanged = true
-- Do code here
end
end
end)
Alternatively, you could use :GetPropertyChangedSignal() but either way works.
Instances inheriting from ValueBase each have special Changed events that only fire when their value changes so it’s functionally equivalent to using GetPropertyChangedSignal for other instances. The Changed events will also fire with the new value which is more convenient if you want to check directly. In the context of an xValue object, use Changed.
value2.Changed:Connect(function (newValue)
-- Do things here. Changed only fires when the Value is changed.
end)