OnClientEvent doesn't change BoolValue

Hi!

I’m losing my mind here, so please hear me out.
What I want to achieve is, when player presses N, it signals the server, the server checks if the noctovision is set to true, and fires coresponding remote event back to client. Client gets the signal, and turns on the gui.

The problem is, it isn’t changing the value of ScreenGui (CameraStatic) to enabled, but it doesn’t give me any error, and when I use print to check if everything went smoothly, it prints out everything fine, and I don’t really know what to do. Thanks for your help!!

Here is my script handling the remotes:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("CameraOnOff")
local on = game:GetService("ReplicatedStorage"):WaitForChild("CameraOn")
local off = game:GetService("ReplicatedStorage"):WaitForChild("CameraOff")

remote.OnServerEvent:Connect(function(player)
	local CameraOnOff = game.Workspace[player.Name]:WaitForChild("CameraOnOff")
	local CameraPercent = game.Workspace[player.Name]:WaitForChild("CameraBatteryPercent")
	if CameraOnOff.Value == false and CameraPercent.Value > 0 then
		CameraOnOff.Value = true
		on:FireClient(player)
		print("lol")
	end
	if CameraOnOff.Value == true and CameraPercent.Value > 0 then
		CameraOnOff.Value = false
		off:FireClient(player)
	end
end)

Here is my local script that should turn on the screengui but it doesn’t

local player = script.Parent.Parent.Parent.Parent
local lightning = game:GetService("Lighting")
local colorcorrection = game.Lighting.ColorCorrection
local CameraStatic = script.Parent.Parent
local equip = game.Workspace.Sounds.CameraPickUp
local deequip = game.Workspace.Sounds.CameraDown
local headlight = Instance.new("PointLight")
headlight.Enabled = false
headlight.Parent = game.Workspace:WaitForChild(player.Name):WaitForChild("Head")
headlight.Range = 24
headlight.Brightness = 0.65
local light = game.Workspace:WaitForChild(player.Name).Head.PointLight
local remoteonoff = game:GetService("ReplicatedStorage"):WaitForChild("CameraOnOff")
local on = game:GetService("ReplicatedStorage"):WaitForChild("CameraOn")
local off = game:GetService("ReplicatedStorage"):WaitForChild("CameraOff")

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.N then
		remoteonoff:FireServer()
	end
	

end)

on.OnClientEvent:Connect(function()
	print("enabling")
	CameraStatic.Enabled = true  --problem happens here
	print("i did it") --everything prints
end)

off.OnClientEvent:Connect(function()
	CameraStatic.Enabled = false
end)

Are you sure your ScreenGui is really not enabled? Have you went into the PlayerGui folder for checking if the ScreenGui is enabled or not? Maybe your frames or textlabels are invisible? Try printing the value of enabled in the local script, see if it prints true or false.

Also, you can easily get the (Local) player by doing game.Players.LocalPlayer (in a LocalScript).

I’m 100 percent sure, since in game when I’m enabling it with explorer it works, I’ll post a video in a while showing it

1 Like

Here is the video

1 Like

ScreenGui’s Enabled property never works :frowning: I always add a frame below the screenGui because the Visible property on it works, and all the children of the frame are invisible, advice: add Frame and then edit your scripts to another parent such as

--before
local player = script.Parent.Parent.Parent.Parent
--afterwards 
local player = script.Parent.Parent.Parent.Parent.Parent

Can you try printing something in the other OnClientEvent. Also where is your script located in the explorer.

lol didn’t notice that while it was enabling it, it was also deenabling it, should have checked it.

Thanks for all the help you guys gave me, also, I’ll change the script parent parent part to game.Players.LocalPlayer

2 Likes

No worries. I think this is because you’re setting the value to true when when it’s false, and therefore it satisfies the second if statement. You should try using an else statement instead.

remote.OnServerEvent:Connect(function(player)
	local CameraOnOff = game.Workspace[player.Name]:WaitForChild("CameraOnOff")
	local CameraPercent = game.Workspace[player.Name]:WaitForChild("CameraBatteryPercent")
	if CameraOnOff.Value == false and CameraPercent.Value > 0 then
		CameraOnOff.Value = true
		on:FireClient(player)
		print("lol")
	elseif CameraOnOff.Value == true and CameraPercent.Value > 0 then
		CameraOnOff.Value = false
		off:FireClient(player)
	end
end)