Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I update gui with filtering enabled?

So I am trying to update a PlayerGUI called GunGui but it's just not outputting anything in console. The recent filtering enabled disallows me from just using a to do this.

LOCALSCRIPT

local ReplicatedStorage = game:GetService("ReplicatedStorage").PlayerEvents
local updateWeaponGui = ReplicatedStorage:WaitForChild("UpdateWeaponGui")

while wait(.1) do
	updateWeaponGui:FireClient()
end

SCRIPT

local ReplicatedStorage = game:GetService("ReplicatedStorage").PlayerEvents
local updateWeaponGui = ReplicatedStorage:WaitForChild("UpdateWeaponGui")

local function execute(player)
    local gui = player:FindFirstChild("GunGui")
	
	for _,v in pairs(player.Character:GetChildren()) do
		if v.ClassName == "Tool" then
			if (v:FindFirstChild("Ammo")) and (v:FindFirstChild("GunType")) then
				if (v.Ammo.Value > 0) then
					gui.Main.name.Text = "Gun Name: " .. v.GunName.Value
					gui.Main.Ammo.Text = "Ammo: " .. v.Ammo.Value
					gui.Main.Type.Text = "Gun Type: " .. v.GunType.Value
					gui.Main.Reload.Visible = false
					gui.Main.NoGun.Visible = false
				elseif (v.Ammo.Value <= 0) then
					gui.Main.name.Text = "Gun Name: " .. v.GunName.Value
					gui.Main.Ammo.Text = "Ammo: " .. v.Ammo.Value
					gui.Main.Type.Text = "Gun Type: " .. v.GunType.Value
					gui.Main.Reload.Visible = true
					gui.Main.NoGun.Visible = false
				end
			else
				gui.Main.name.Text = "Gun Name: N/A"
				gui.Main.Ammo.Text = "Ammo: N/A"
				gui.Main.Type.Text = "Gun Type: N/A"
				gui.Main.Reload.Visible = false
				gui.Main.NoGun.Visible = true
			end
		else
			gui.Main.name.Text = "Gun Name: N/A"
			gui.Main.Ammo.Text = "Ammo: N/A"
			gui.Main.Type.Text = "Gun Type: N/A"
			gui.Main.Reload.Visible = false
			gui.Main.NoGun.Visible = true
		end
	end
	
end

updateWeaponGui.OnClientEvent:Connect(execute)

2 comments

0

I don't think you can access a player's gui serverside

0

Wait() shouldn't be a condition.

1 answer

You seem to have mixed up the "Client" and "Server" names for your events. When you are firing an event from a client, to the server, you use EventName:FireServer() and the server can receive the event with EventName.OnServerEvent:Connect(function).

2 comments

0

So when I equip the tool, nothing happens still. And since I can't access a playergui server side how am I supposed to get this sorted?

This discussion is preserved as it was. New answers, comments, and votes are closed.