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 can share a GUI to all clients?

Hello,just for further info,this is an alt account i used because i didnt remember my password on my main acc.

So,I was trying to make a player when it clicks on a GUI button,it creates a clone of it and passes it to all players in the server.I havent figured it out yet and its driving me crazy! Also tried some dev forum solutions,still nothing.

I have tested it out with a binable event and remote event (Not sure if i need to use a Remote Function) In the binable event,it works,but it only appears to the player who pressed it

I am using a remote event:

Local

local UIS = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local Erase = script.Parent.Parent:WaitForChild("Erase")
local Send = script.Parent.Parent:WaitForChild("Send")
local point = script.Parent:FindFirstChild("Pointer")
local canvas = script.Parent

local hold = false

function paint(X, Y)
	local gui_X = canvas.AbsolutePosition.X
	local gui_Y = canvas.AbsolutePosition.Y
	
	local offset = Vector2.new(math.abs(X - gui_X), math.abs(Y - gui_Y - 36))
	point.Position = UDim2.new(0, offset.X, 0 , offset.Y)
	
	if hold == false then return end
	
	local pixel = point:Clone()
	pixel.Name = "Pixel"
	pixel.Parent = canvas
end

Erase.MouseButton1Click:Connect(function()
	local children = canvas:GetChildren()
	
	for i, child in pairs(children) do
		if child.Name == "Pixel" then
			child:Destroy()
		end
	end
end)

canvas.MouseMoved:Connect(paint)

canvas.MouseEnter:Connect(function()
	point.Visible = true
end)

canvas.MouseLeave:Connect(function()
	point.Visible = false
end)

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		hold = true
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		hold = false
	end
end)
--script.Parent.Parent, player.Name
Send.MouseButton1Click:Connect(function(player)
	game.ReplicatedStorage.RemoteEvents.ShareEvid:FireServer(player)
	script.Parent.Parent.Draw.Visible = false
		script.Parent.Parent.Send.Visible = false
		script.Parent.Parent.Erase.Visible = false
		script.Parent.Top.Visible = false
end)

game.ReplicatedStorage.RemoteEvents.ShareEvid.OnClientEvent:Connect(function(player)
	local Gui = plr.PlayerGui.Evidence.Draw:Clone()
	Gui.Top.Text = plr.Name.."'s Evidence"
	Gui.Parent = player
	
	return Gui
	
	
	
end)

Yes,it is a canvas GUI.

Server

game.ReplicatedStorage.RemoteEvents.SetOrder.OnServerEvent:Connect(function()
	local Teams = game.Teams
	
	for i, v in pairs(Teams.Innocent:GetPlayers()) do
		local Char = v.Character
		Char.HumanoidRootPart.CFrame = workspace.InnoTP.CFrame
	end
	
	for i, v in pairs(Teams.Blamed:GetPlayers()) do
		local Char = v.Character
		Char.HumanoidRootPart.CFrame = workspace.BlameTP.CFrame
	end
	
	workspace.Separate.CanCollide = true
	wait(8)
	workspace.Separate.CanCollide = false
end)
--The part up is another thing,recommend to not pay attention to it

game.ReplicatedStorage.RemoteEvents.ShareEvid.OnServerEvent:Connect(function(player)
	for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        game.ReplicatedStorage.RemoteEvents.ShareEvid:FireClient(player)
    end
end)

And a bonus:Top is not a valid member of ScreenGui? While its parented to the draw frame.

If you could include example code it would be better

Sorry,i am not that good in scripting. Thanks,Have a nice day.

2 answers

this is the change to the serverscript starting at line 20

game.ReplicatedStorage.RemoteEvents.ShareEvid.OnServerEvent:Connect(function(players)
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
game.ReplicatedStorage.RemoteEvents.ShareEvid:FireAllClients(player)
end
end)

p.s I hope this helped this i signed up just to answer this question so this is my first post.

3 comments

0

It didnt worked,still,it shows nothing,but thanks for at least trying

0

what is the error you are getting?

0

It doesnt print any error

First, in your Server Script, instead of Firing Clients separately, you can Fire all clients at once:

game.ReplicatedStorage.RemoteEvents.ShareEvid:FireAllClients()

And the line above it, where server is receiving, you can do:

game.ReplicatedStorage.RemoteEvents.ShareEvid.OnServerEvent:Connect(function(plr)

And on line 67, I assume you are using:

game.ReplicatedStorage.RemoteEvents.ShareEvid.OnClientEvent:Connect(function(player)

Instead, you can simply do:

game.ReplicatedStorage.RemoteEvents.ShareEvid.OnClientEvent:Connect(function()

Then, you can make the Local Player the parent of the Gui:

Gui.Parent = plr:WaitForChild("PlayerGui")

I assume the Gui is already present in Starter Gui. This is how your end part of Local script moght look:

game.ReplicatedStorage.RemoteEvents.ShareEvid.OnClientEvent:Connect(function()
    	local Gui = plr:WaitForChild("PlayerGui").Evidence.Draw:Clone()
    	Gui.Parent = plr:WaitForChild("PlayerGui")
    	Gui.Top.Text = plr.Name.."'s Evidence"

    	return Gui
end)

If it doesn't work, lemme know the errors.

Please Upvote and lemme know if it helped!

Edit: You told me that a player draws something on Canvas, so it shows on every player's Gui.

It's just an eg, which does not represent your script in any way. Take the idea from here, and implement it in your game.

for that, u can do:

-- Make an empty Screen Gui and name it CanvasToAll

--Local script for button
local player = game.Players.LocalPlayer
local canvas = player:WaitForChild("PlayerGui").CanvasGui:GetChildren() -- It will get contents from the Gui
local canvasG = player:WaitForChild("PlayerGui").CanvasGui

script.Parent.MouseButton1Click:Connect(function()
	if game.ReplicatedStorage.CanvasBool.Value == true then
		game.ReplicatedStorage.CanvasR:FireServer(canvas)
	end
end)

game.ReplicatedStorage.CanvasR.OnClientEvent:Connect(function(canvasC)
	for i, v in pairs(canvasC) do
		local clone = v:Clone()
		clone.Parent = canvasG
	end
end)

-- Server script in ServerScriptService
game.ReplicatedStorage.CanvasR:OnServerEvent:Connect(function(plr, canvas)
game.ReplicatedStorage.CanvasBool.Value = true
	if game.ReplicaredStorage.CanvasBool.Value == true then
		for i, v in pairs(canvas) do
			local clone = v:Clone()
			clone.Parent = game.ReplicatedStorage.Canvas -- Made a folder in 		ReplicatedStorage called Canvas
		end
		wait(1)
		local canvasContents = game.ReplicatedStorage.CanvasR:GetChildren()

		game.ReplicatedStorage.CanvasR:FireAllClients(canvasContents)
		game.ReplicatedStorage.CanvasBool.Value = false
	end
end)

-- Added CanvasBool as a bool value to prevent overlapping if button is pressed simultaneously by two or more players

Hope it helps! Lemme know.

14 comments

0

Didnt work,still it show nothing,and no error is shown on the output,but thanks for trying!

0

Can you add prints before and after firing remote events? I doubt there's something to be in Remote Event only

0

Hmm... I have added them,they all print when i click the send button

0

It prints first "I clicked the send button" then "the remote has ran on its server call" and finally "the remote has ran on its client call"

0

I assume the Gui is in the starteGui by default, so try removing cloning thing.

0

kinda basic stuff but are all of the GUI elements enabled / visible when you're trying to display it?

0

well, you have to check the properties in order to get your answer, but if you are talking about by default, it is eanbled/visible

0

Giving more information,a player draws something in the canvas gui,then when it press its send button ,its drawing its showed to all players

0

I edited my answer, try checking that out!

0

Thanks,gonna check if it works later,i am occupied right now

0

I am confused,i saw the script,does the canvas remote events needs some child or something?

0

And tried it and still nothing,i can invite you to the roblox studio if you wanna see the objects tho,or i can just tell them

0

@Samyak7649, this is my discord. DM me there. It will be easier to help you there.

0

Sent friend request,or theres other way?

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