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 get this GUI to replicate to other players' screens?

I knew this would happen, I'm just not sure how to fix it. If it isn't already obvious this is a localscript.

local player = game.Players.LocalPlayer
local background = script.Parent:FindFirstChild("Background")
local text = background:FindFirstChild("PlayerName")

script.Parent.Parent = player.PlayerGui
local playername = player.Character:WaitForChild("PlayerName")

while wait(playername) do
	function getplayername()
		if player and playername then
			background:TweenPosition(UDim2.new(0.187, 0, 0, 0), "Out", "Back", 2) 
			text.Text = playername.Value.." Wins!"
			wait(5)
			background:TweenPosition(UDim2.new(0.187, 0, -1, 0), "In", "Back", 2) 
			playername:Destroy()
		end
	end
	getplayername()
end

How would I make this replicate to other screens?

3 comments

0

try using client event

0

How do I do that?

1 answer

As DesiredRep commented, you need to use Client Event, which is a part of Replicated Events (and Functions)

You will need the LocalScript you already have, as well as a Server Script within ServerScriptServices For this example, I used a Remote Event inside Replicated Storage named "RemoteEvent"

LocalScript

local player = game.Players.LocalPlayer
local background = script.Parent.Background
local text = background.PlayerName
local debounce = true

script.Parent.Parent = player.PlayerGui
local playername = player.Character:WaitForChild("PlayerName")
local remote = game.ReplicatedStorage.RemoteEvent

remote.OnClientEvent:Connect(function(msg)
	print(msg)
	if msg == "TweenOut" then
		script.Parent.Background:TweenPosition(UDim2.new(0.187, 0, 0, 0), "Out", "Back", 2) 
		text.Text = (playername.Value.." Wins!")
	elseif msg == "TweenIn" then
		script.Parent.Background:TweenPosition(UDim2.new(0.187, 0, -1, 0), "In", "Back", 2) 
	end
end)

while true do
	local stringvalue = player.Character:FindFirstChild("PlayerName")
	if stringvalue ~= nil then
		if debounce == false then return end
		debounce = false
		print("Loop Start")
		function getplayername()
			if player and playername then
			print("Function Start")
			playername:Destroy()
				remote:FireServer("Out")
				wait(5)
				remote:FireServer("In")
				wait(2)
				debounce = true
			end
		end
		getplayername()
	else
		wait(1)
	end
end

Server Script

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player, setup)
	print(setup)
	if setup == "Out" then
		remote:FireAllClients("TweenOut")
	elseif setup == "In" then
		remote:FireAllClients("TweenIn")
	end
end)

The FireAllClients event can be used to make this occur for all players in the game. The reason you have to send it to the server first is so that it can be then sent to all clients, not just the one player. There is not FireAllClients on the Client-Side.

2 comments

0

This didn't work, tested it on a server and only the screen of the player who won showed the gui.

0

Output is working, function appears to be playing, it is replicating correctly.

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