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)
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 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?
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.
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).
I’m not really sure what “hierarchy” means but i think you meant this? Main Script The folder with the values its trying to get
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.