Bool value not changing

I have a region3 that surrounds the player that summoned it and the other players in the region3 has a bool value that changes making their camera shake but the problem here is that everything else works but the bool value only changes sometime, sometime meaning that it works the first, third, fifth and so on. I’ve tried debugging it multiple times and it runs it just that the values changes like i said before, first, third, and so on. I’m sorry if i’m not that good at explaining so please ask me anything about it.

Finding other players in Region3:

local screamAreaClone = screamArea:Clone()
		screamAreaClone.Parent = workspace
		screamAreaClone.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,0,0)
		screamAreaClone.Orientation = Vector3.new(0,0,0)
		screamAreaClone.Anchored = true
		
		local pos1, pos2 = (screamAreaClone.Position - (screamAreaClone.Size/2)), (screamAreaClone.Position + (screamAreaClone.Size/2))	
		local region = Region3.new(pos1, pos2)
		local playersInRegion = workspace:FindPartsInRegion3(region, player.Character)
		local playersFound = {}
		for _, part in pairs(playersInRegion) do
			if part.Parent:FindFirstChild('Humanoid') and part.Parent:FindFirstChild('ShakeCam') then
				print(part.Parent.Name..' has been found ya')
				playersFound[part.Parent.Name] = part.Parent
			end
		end
		for _, enemyCharacter in pairs(playersFound) do
			cameraShake:InvokeServer(player, enemyCharacter)
		end
		screamAreaClone.Parent = nil

all of this is working just putting this here if you don’t understand what i’m saying

Changing the Bool Value:

function cameraShake:OnServerInvoke(player, enemy)
	enemy.ShakeCam.Value = not enemy.ShakeCam.Value
end
1 Like

If this is in a (Server) Script, try using a couple of prints to double check when it works and when it doesn’t.
Try using this

function cameraShake:OnServerInvoke(player, enemy)
	enemy.ShakeCam.Value = not enemy.ShakeCam.Value
	print(enemy.ShakeCam.Value) -- Will print value of the BoolValue.Value
end


Also I would recommend using enemy.ShakeCam.Value = false

1 Like

that function you mention is in a server script i also have tried printing out the bool value and it kept on the pattern of true,false,true,false and so on
And the reason for me not using enemy.ShakeCam.Value = false is because if i use that it will only work once and never again

1 Like

Is the event you are invoking a RemoteFunction or BindableFunction

1 Like

Do you have another function that changes the value under certain circumstances?

1 Like

the event is being invoke through a remotefunction

1 Like

Then just making sure that it is being invoked in a local script right

1 Like

yes i do but it uses the changed event

yes it is being invoked in a local script

On the server try this.

local function shakeCamera(player, enemy)
    enemy.ShakeCam.Value = not enemy.ShakeCam.Value
end

cameraShake.OnServerInvoke = shakeCamera

In the local script, remove the player parameter from the :InvokeServer() event.

Edit: the reason why you should remove it is because the player is automatically passed as an argument from local script to the server

i tried what you said but sadly it still does not work and the same thing keeps on happening

Well, I see why now. In your for loop that passes the enemy into the invoke, because of the loop, you are invoking multiple times which is why it keeps flipping back and forth

Edit:
I’d also recommend doing print(enemy.Name.. " - Passed Enemy Character") after the enemy.ShakeCam.Value = ... code. This would make sure that the same character is not being changed multiple times.