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
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
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
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.