Script not reading BoolValue correctly?

So I’ve got a local script that needs to signal the server that the player is currently in ‘block placement’ mode, then a click detector script on a block checks the value of the isPlacing boolean to see if it is currently true. If it is, go ahead and place the block.
I decided to use a BoolValue stored in ReplicatedStorage because I wasn’t sure if a RemoteEvent would work correctly for this purpose, but my solution does seem adequate.
When I test my game, I see the BoolValue where I wanted it, and I can see it toggle on and off as I go in and out of block placing mode.
However, whenever I try to read the value of the bool from the click detector script, it always returns false. I’m tearing my hair out trying to figure out why, because nothing makes sense. I’ve checked the GetFullName path from both scripts and they match up. If I change the name of the BoolValue from within the click detector script, it changes the same one that was toggled on or off. Also, if I change the value of it to true from within the server script, it reads it correctly.
From everything I can tell, both scripts are using the exact same BoolValue and both can modify it. But no matter what, when I try to read it from the server script, it returns false.
Does anyone have any idea what’s going on here?

1 Like

Changes made by a LocalScript don’t replicate to the server. This is primarily for security, because it means that most hacks don’t replicate either. You need to use a RemoteEvent for this.

3 Likes

I was wondering if that was it as well, but when I selected the actual BoolValue object in ReplicatedStorage as I was testing it, I could see the value changing from my local script. That’s the reason why I used ReplicatedStorage: because it’s supposed to be accessible from both client and server.

Unless that’s just because I was testing on just my local machine? I think you’re right, but then it doesn’t make any sense that the value was updating. I’ll work a RemoteEvent into it now.

EDIT: I went ahead and made a RemoteEvent to change the value of my BoolValue and it all works now. I’m still annoyed that it showed the value changing, but it makes sense considering how the basic testing works. Thanks for the help!

1 Like