I’m probably just being stupid but can anyone see why this isn’t changing a value?
local RS = game:GetService("ReplicatedStorage")
RS.ESRadio.OnServerEvent:Connect(function(Plr, Task, State)
if Task == "RadioStat" then
if State == true then
Plr.PlayerGui:FindFirstChild("ESRadio_GUI").Frame.Status.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
Plr.PlayerGui:FindFirstChild("ESRadio_GUI").Frame.Status.State.Value = false
else
Plr.PlayerGui:FindFirstChild("ESRadio_GUI").Frame.Status.BackgroundColor3 = Color3.fromRGB(85, 170, 0)
Plr.PlayerGui:FindFirstChild("ESRadio_GUI").Frame.Status.State.Value = true
end
end
end)
Well, your code doesn’t really make sense to me. Based on the code it seems to be a server script. However, gui changes should be done in local scripts.
I don’t understand. Are you trying to fire the event to the client or the server? If the server, then make sure your script is a ServerScript, not a LocalScript.
on the client side you should use OnClientEvent in this way
local RS = game:GetService("ReplicatedStorage")
local Plr = game:GetService("Players").LocalPlayer
-- wait for instances to be replicated
RS:WaitForChild("ESRadio")
Plr:WaitForChild("PlayerGui"):WaitForChild("ESRadio_GUI"):WaitForChild("Frame"):WaitForChild("Status"):WaitForChild("State")
RS.ESRadio.OnClientEvent:Connect(function(Task, State)
if Task == "RadioStat" then
if State == true then
Plr.PlayerGui.ESRadio_GUI.Frame.Status.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
Plr.PlayerGui.ESRadio_GUI.Frame.Status.State.Value = false
else
Plr.PlayerGui.ESRadio_GUI.Frame.Status.BackgroundColor3 = Color3.fromRGB(85, 170, 0)
Plr.PlayerGui.ESRadio_GUI.Frame.Status.State.Value = true
end
end
end)
and on the server side, in some script, you should have something like this
local event: RemoteEvent = game:GetService("ReplicatedStorage").ESRadio
game:GetService("Players").PlayerAdded:Connect(function (player)
-- some code
event:FireClient(player, "RadioStat", true)
--some code
event:FireClient(player, "RadioStat", false)
end)
Could you elaborate on what you are trying to do overall, because your code seems to be changing a value in PlayerGui, which can be done through the Client side most efficiently.
I’ve just figured out the issue. To answer your question though, if I change a value on the client the server cannot see that so when I get the server to check a value it won’t have updated.
More like on the client side you should not wait for such (an) instance(s) to be replicated since as brought about in several threads, local scripts execute after instances placed in R.S that exist implicitly (e.g those that you create and set the Parent property for through RobloxStudio) have replicated.
-- wait for instances to be replicated
RS:WaitForChild("ESRadio")
That is impertinent to the matter at hand - it is generally recommended to execute such changes locally but altering GUI related settings shouldn’t make such a difference in this scenario that it would cause the code to function improperly or cause an undesired outcome (and judging by the screenshot the code is in a local script anyway, I second the idea that it doesn’t make sense at all though what with where the code is placed, server-sided code placed in a local script).
Directing my response to the topic.
The problem here is likely to be that the code which should’ve been placed server-side is placed to run on the client. Didn’t go through it completely but MillaGamerF’s response looks like the way to do it.