Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i can share a GUI to all clients?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

0
It didnt worked,still,it shows nothing,but thanks for at least trying yuni_Boy1234 320 — 3y
0
what is the error you are getting? omgcchheeessee 0 — 3y
0
It doesnt print any error yuni_Boy1234 320 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

0
Didnt work,still it show nothing,and no error is shown on the output,but thanks for trying! yuni_Boy1234 320 — 3y
0
Can you add prints before and after firing remote events? I doubt there's something to be in Remote Event only BestCreativeBoy 1395 — 3y
0
Hmm... I have added them,they all print when i click the send button yuni_Boy1234 320 — 3y
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" yuni_Boy1234 320 — 3y
View all comments (10 more)
0
I assume the Gui is in the starteGui by default, so try removing cloning thing. BestCreativeBoy 1395 — 3y
0
kinda basic stuff but are all of the GUI elements enabled / visible when you're trying to display it? AlexTheCreator 461 — 3y
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 BestCreativeBoy 1395 — 3y
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 yuni_Boy1234 320 — 3y
0
I edited my answer, try checking that out! BestCreativeBoy 1395 — 3y
0
Thanks,gonna check if it works later,i am occupied right now yuni_Boy1234 320 — 3y
0
I am confused,i saw the script,does the canvas remote events needs some child or something? yuni_Boy1234 320 — 3y
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 yuni_Boy1234 320 — 3y
0
@Samyak7649, this is my discord. DM me there. It will be easier to help you there. BestCreativeBoy 1395 — 3y
0
Sent friend request,or theres other way? yuni_Boy1234 320 — 3y

Answer this question