Script not affecting playergui

it only affects the screengui on the server not for the clients, please tell me how to fix thanks.

local TweenService = game:GetService("TweenService")
local GroupService = game:GetService("GroupService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local GroupId = 33325443 -- Replace with your group ID
local RequiredRank = 200

local AnnouncementSystem = game.StarterGui.AnnouncementSystem

local Frame = AnnouncementSystem.AnnouncementFrame
local TextLabel = Frame.AnnouncementText

local startPosition = UDim2.new(0.337, 0, -0.4, 0)
local endPosition = UDim2.new(0.337, 0, 0.07, 0)

local tweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tweens = {
	TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
	TweenService:Create(Frame, tweenInfo, { Position = startPosition })
}

function ShowGui()
	print("Showing GUI")
	tweens[1]:Play() -- Play the tween from start to end position
end

function HideGui()
	print("Hiding GUI")
	tweens[2]:Play() -- Play the tween from end to start position
end

local function ShowAnnouncement(message)
	print("Showing Announcement with message: " .. message)
	TextLabel.Text = message
	ShowGui()
	wait(5)
	HideGui()
end

game.Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game")
	player.Chatted:Connect(function(message)
		print(player.Name .. " said: " .. message)
		if message:sub(1, 2) == ":a" then
			if player:GetRankInGroup(GroupId) >= RequiredRank then
				local announcementMessage = message:sub(4)
				ShowAnnouncement(announcementMessage)
			else
				print(player.Name .. " does not have the required rank. Rank is: " .. tostring(player:GetRankInGroup(GroupId)))
			end
		end
	end)
end)

-- Replicate the GUI change to all players when the RemoteEvent is fired
ReplicatedStorage.ReplicateGuiChange.OnServerEvent:Connect(function(player, show, announcementMessage)
	local playerGui = player:FindFirstChildOfClass("PlayerGui")
	if playerGui then
		local playerAnnouncementSystem = playerGui.AnnouncementSystem
		if playerAnnouncementSystem then
			local playerFrame = playerAnnouncementSystem.AnnouncementFrame
			if playerFrame then
				print("Replicating GUI change")
				-- Update the TextLabel directly
				ShowAnnouncement(announcementMessage)
				-- Then, if you want to show/hide the GUI, you can do so here
				-- playerFrame.Visible = show
			end
		end
	end
end)

You can try:

  1. First, create a RemoteEvent in ReplicatedStorage to send a message from the server to all clients.
  2. Update the ShowAnnouncement function to send the message to the clients using the RemoteEvent.
  3. Modify the client-side script to listen for this event and update the GUI accordingly.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GroupService = game:GetService("GroupService")

local GroupId = 33325443 -- Replace with your group ID
local RequiredRank = 200

local AnnouncementSystem = game.StarterGui.AnnouncementSystem
local Frame = AnnouncementSystem.AnnouncementFrame
local TextLabel = Frame.AnnouncementText

local startPosition = UDim2.new(0.337, 0, -0.4, 0)
local endPosition = UDim2.new(0.337, 0, 0.07, 0)

local tweenInfo = TweenInfo.new(
    1,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)

local tweens = {
    TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
    TweenService:Create(Frame, tweenInfo, { Position = startPosition })
}

function ShowGui()
    print("Showing GUI")
    tweens[1]:Play() -- Play the tween from start to end position
end

function HideGui()
    print("Hiding GUI")
    tweens[2]:Play() -- Play the tween from end to start position
end

local function ShowAnnouncementToPlayer(player, message)
    print("Showing Announcement with message: " .. message)
    TextLabel.Text = message
    ShowGui()

    wait(5)
    HideGui()

    -- Replicate the announcement to the client
    ReplicatedStorage.ReplicateGuiChange:FireClient(player, true, message)
end

game.Players.PlayerAdded:Connect(function(player)
    print(player.Name .. " joined the game")
    player.Chatted:Connect(function(message)
        print(player.Name .. " said: " .. message)
        if message:sub(1, 2) == ":a" then
            if player:GetRankInGroup(GroupId) >= RequiredRank then
                local announcementMessage = message:sub(4)
                ShowAnnouncementToPlayer(player, announcementMessage)
            else
                print(player.Name .. " does not have the required rank. Rank is: " .. tostring(player:GetRankInGroup(GroupId)))
            end
        end
    end)
end)

And for the local script (StarterPlayer Scripts):


local ReplicateGuiChange = ReplicatedStorage:WaitForChild("ReplicateGuiChange")

ReplicateGuiChange.OnClientEvent:Connect(function(show, announcementMessage)
    local playerGui = game.Players.LocalPlayer:FindFirstChildOfClass("PlayerGui")
    if playerGui then
        local playerAnnouncementSystem = playerGui.AnnouncementSystem
        if playerAnnouncementSystem then
            local playerFrame = playerAnnouncementSystem.AnnouncementFrame
            if playerFrame then
                print("Replicating GUI change")
                playerFrame.Visible = show
                playerFrame.AnnouncementText.Text = announcementMessage
            end
        end
    end
end)
1 Like

These are my 2 modified scripts and they still don’t work.

serverscript

local GroupId = 33325443 -- Replace with your group ID
local RequiredRank = 200

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GroupService = game:GetService("GroupService")
local TweenService = game:GetService("TweenService")

local AnnouncementSystem = game.StarterGui.AnnouncementSystem
local Frame = AnnouncementSystem.AnnouncementFrame
local TextLabel = Frame.AnnouncementText

local startPosition = UDim2.new(0.337, 0, -0.4, 0)
local endPosition = UDim2.new(0.337, 0, 0.07, 0)

local tweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tweens = {
	TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
	TweenService:Create(Frame, tweenInfo, { Position = startPosition })
}

local function ShowGui()
	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tweens = {
		TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
		TweenService:Create(Frame, tweenInfo, { Position = startPosition })
	}
	print("Showing GUI")
	tweens[1]:Play() -- Play the tween from start to end position
end

local function HideGui()
	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tweens = {
		TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
		TweenService:Create(Frame, tweenInfo, { Position = startPosition })
	}
	print("Hiding GUI")
	tweens[2]:Play() -- Play the tween from end to start position
end

function ShowAnnouncementToPlayer(player, message)
	print("Showing Announcement with message: " .. message)
	TextLabel.Text = message
	ShowGui()

	wait(5)
	HideGui()

	-- Replicate the announcement to the client
	ReplicatedStorage.ReplicateGuiChange:FireClient(player, true, message)
end


game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		print(player.Name .. " said: " .. message)
		if message:sub(1, 2) == ":a" then
			if player:GetRankInGroup(GroupId) >= RequiredRank then
				local announcementMessage = message:sub(4)
				ShowAnnouncementToPlayer(player, announcementMessage)
			else
				print(player.Name .. " does not have the required rank. Rank is: " .. tostring(player:GetRankInGroup(GroupId)))
			end
		end
	end)
end)

local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicateGuiChange = ReplicatedStorage:WaitForChild("ReplicateGuiChange")
local TweenService = game:GetService("TweenService")

local AnnouncementSystem = game.StarterGui.AnnouncementSystem
local Frame = AnnouncementSystem.AnnouncementFrame
local TextLabel = Frame.AnnouncementText

local startPosition = UDim2.new(0.337, 0, -0.4, 0)
local endPosition = UDim2.new(0.337, 0, 0.07, 0)

local tweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tweens = {
	TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
	TweenService:Create(Frame, tweenInfo, { Position = startPosition })
}

local function ShowGui()
	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tweens = {
		TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
		TweenService:Create(Frame, tweenInfo, { Position = startPosition })
	}
	print("Showing GUI")
	tweens[1]:Play() -- Play the tween from start to end position
end

local function HideGui()
	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tweens = {
		TweenService:Create(Frame, tweenInfo, { Position = endPosition }),
		TweenService:Create(Frame, tweenInfo, { Position = startPosition })
	}
	print("Hiding GUI")
	tweens[2]:Play() -- Play the tween from end to start position
end

ReplicateGuiChange.OnClientEvent:Connect(function(show, message)
	if show then
		print("Replicating GUI change")
		TextLabel.Text = message
		ShowGui()
	else
		HideGui()
	end
end)

Can you provide information of what errors you are encountering?

It changes the GUI on the server but when on the client it doesn’t affect the playergui

I mean, the output from the changes i made and you edited

It is because you are doing

game.StarterGui.AnnouncementSystem

It has to be:

local Players = game:GetService("Players")

local AnnouncementSystem = Players.LocalPlayer.PlayerGui.AnnouncementSystem

for it to make changes to the GUI under PlayerGui.

Obviously this script needs to be a LocalScript on the client.

1 Like

Like basically everyone here has said, you are changing startergui. When a player joins, they are given a copy of whatever’s in StarterGui. So even if you change something later in the game, it won’t update.

I suggest using Remote Events like @sammy23906 said. With remote events, a server script can tell a player’s client to do something. So on the client you would have code that sets up an event listener and changes the text to whatever, while on the server you would have the rest of your script that will fire the client and tell it to do whatever.