Script thinks value is false

I’m trying to make so that if the provided value is true it will do a certain action, but it always says the value is false even if the value is true.

local rep = game:GetService("ReplicatedStorage")


game.Players.PlayerAdded:Connect(function(player)
	task.wait(5)
	for _,  v in pairs(script.Parent:GetChildren()) do
		local tar = player:WaitForChild("savedCubes"):FindFirstChild(v.Name)
		warn("agog")
		
		if tar.Value then
			warn(tar.Name.." was found last session")
			rep:FindFirstChild("requestDestroy"):FireClient(player,v)
			warn("event successfully fired")
			task.wait(3)
		else
			warn("player didnt find "..tar.Name.." last session.")
		end
	end
end)

image

image

This is because you are changing the value client-sidedly and expecting it to change server-sidedly as well.
Instead use a RemoteEvent to send a message from client to server to change the value server-sidedly.

I’m not changing any values! The value was true by default in the server :sweat_smile:

I think we’ll need to see the hierarchy you have set up to figure out what is going on, as it looks like the script running this code is indeed a Server Script.

Is the Rock Cube property generated or a permanent descendant of this Script?

Have you also tried printing out the value using the Command bar to see if the result matches?

1 Like

instead of

if tar.Value then
--code

do

if tar.Value == true then
--code

I believe your code is not working because you are setting tar to a child of savedCubes.

  1. It’s generated,
  2. It doesn’t print the same value

I tried that and it unfortunately doesn’t work :sweat_smile:

That’s essentially the same thing.

Same thing mate, setting it default as if object.Value then is just default set to true

May I see your hierarchy? I need to see more of the problem to get a grasp of the situation.

Not really. The first one checks if the value is truthy, the second one checks if its true. Depending on your circumstances this distinction can be very important and ignoring that distinction can lead to unpredictable behaviour. This mix-up case is more common with the not operator or needing to explicitly check for false or nil rather than just falsy.

1 Like

In this scenario I was inferring that they are essentially the same, as a BoolValue instance is being used of which can only be in one of two states (true or false).

Try

if tar.Value then
    --code here
elseif tar.Value == false then
    --code here
end

And if possible check the value during run time on the server.

I’m not really sure what “hierarchy” means but i think you meant this? :sweat_smile:
image Main Script
image The folder with the values its trying to get
image
The values are being generated by getting every BasePart in the Cubes folder and changing them into BoolValues.

And then a datastore loads the values via ServerScriptService

Shouldn’t you wait for the values to be loaded via datastore then? Maybe you check before the values are loaded in which is why the results always come up false.

I tried to make it so that it waits 5 seconds by doing task.wait() to let the values load
but somehow it just does it immediately

I replaced task.wait() with wait() and it seems to work?