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

How make the textlabel visible to all players in the game?

game.ReplicatedStorage.BrickClicked.OnServerEvent:Connect(function(player)
	print("Event picked up")
	local gui = player:WaitForChild("PlayerGui").NAMEOFTHEGUI
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
		gui.TextLabel.Text = tostring(" Host:"..player.Name.."!!")
		gui.TextLabel.Visible = true
		wait(.5)
		gui.TextLabel.Visible = false
		wait(.5)
		gui.TextLabel.Visible = true
		wait(.5)
		gui.TextLabel.Visible = false
		gui.TextLabel.Visible = true
		wait(.5)
		gui.TextLabel.Visible = false
		wait(.5)
		gui.TextLabel.Visible = true
		wait(.5)
		gui.TextLabel.Visible = false

      
end

serverscriptservice script^^^^

I'm trying to make a textlabel visible to all players in the game, after a player has clicked a certain part. The event is being picked up but seems like i messed up the code for what needs to happen.


local HintTest = game.Workspace:WaitForChild("HintTest")

debounce = false

HintTest.ClickDetector.MouseClick:Connect(function()
	if debounce == false then
	debounce = true	
	
	print("I was clicked")
	game.ReplicatedStorage.BrickClicked:FireServer()
	wait(3)
	debounce = false
	end
end)

local script^^^^

2 answers

✓ Accepted answer

This code should fix it, make sure you use :FireAllClient to fire for every client

-- Script
 
local Players = game:GetService("Players")
 
local newPlayerEvent = Instance.new("RemoteEvent")
newPlayerEvent.Parent = game.ReplicatedStorage
newPlayerEvent.Name = "NewPlayer"
 
game.ReplicatedStorage.BrickClicked.OnServerEvent:Connect(function(player)
    print("Event picked up")
    local gui = player:WaitForChild("PlayerGui").NAMEOFTHEGUI
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        gui.TextLabel.Text = tostring(" Host:"..player.Name.."!!")
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        wait(.5)
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        wait(.5)
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false


end

local function onPlayerAdded(player)
	newPlayerEvent:FireAllClients()
end
 
Players.PlayerAdded:Connect(onPlayerAdded)
 
 
-- =======================================

Local script


 
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local player = Players.LocalPlayer
local newPlayerEvent = ReplicatedStorage:WaitForChild("NewPlayerEvent")
local playerGui = player:WaitForChild("PlayerGui")
 

 
local function onNewPlayerFired()
    print("Event picked up")
    local gui = player:WaitForChild("PlayerGui").NAMEOFTHEGUI
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        gui.TextLabel.Text = tostring(" Host:"..player.Name.."!!")
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        wait(.5)
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        wait(.5)
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false


end

	print( "It's working")
end
 
newPlayerEvent.OnClientEvent:Connect(onNewPlayerFired)

Re-edited on 2/Feb/2021 - Fixed grammatical errors

game.ReplicatedStorage.BrickClicked.OnServerEvent:Connect(function(plr)
    print("Event picked up")
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
	local gui = player:WaitForChild("PlayerGui").NAMEOFTHEGUI
        gui.TextLabel.Text = tostring(" Host:"..plr.Name.."!!")
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        wait(.5)
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
        wait(.5)
        gui.TextLabel.Visible = true
        wait(.5)
        gui.TextLabel.Visible = false
  	wait(.5)
        gui.TextLabel.Visible = true -- I added this, so when the animation thing is done it will show the TextLabel
end

The problem was you had 2 variables called player I just changed one of the name

3 comments

0

thx, but that results in the exact same thing.

0

ok I will edit

0

there is no animation and your add only keeps the gui on the player's screen. completely unrelated

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