What is the best way to get a GUIs Absolute Size on a server script

Before you reply with “You can’t get a guis Absolute Size on a server script.” The script I am using has to be on a server script.

I have a script that gets a TextLabels Absolute Size and sets the text size depending on what the Absolute size is. When printing the value of any axis the value printed is always 0. Is there another way of getting the value without the output printing 0?

I’m guessing you are trying to find something in a Player’s gui, If so it is located in game.Players.[Player Name here].PlayerGui I tested this and it works, but if it doesn’t let me know
Edit: Using this way also gives you more control, including creating and destroying gui instances

No I don’t need to find the players gui as the script is in the players gui. I am trying to find the absolute size of a textlabel.

I do not understand, You are using a server script inside the player gui, or have i just misinterpreted that?

The script is parented in the textlabel, so yes the server script is in the player gui.

Idk, maybe you can use RemoteEvents:

--LocalScript
game.ReplicatedStorage.RemoteEvent:Fire(YourGui)

--Script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Gui)
    print(Gui.AbsoluteSize)
end)

But, even if you want to have this on your ServerSide, you can‘t. Guis are LocalSide only, not ServerSide. If you have a Gui on ServerSide, it would like to have a player mouse on the Serverside, and you can‘t this. I mean, a game server can‘t have something that is on your PC, or? Then, why should the Server have a gui from a PC? You can‘t just.

Ok, sorry to say this but, no, why parent a serverscript to something like a gui? If you want or not, you should use a localscript. Why do you want to use a serverscript?

I’m sorry i’m saying this but roblox doesn’t allow that as it is a server script in a client’s gui, it would be better just to run the code on the server using the method i previously said. Roblox just wouldn’t allow that script in the gui to run, try printing something to the output

1 Like

The only reason I parented it to the text label is so it could be easier to access the player gui without using the player added event

As i said:

I am asking why the script has to be on a server script. You not are saying why, you are only saying that this has to be a serverscript, without more details.

I think Eternalove_fan32 meant what is in the script that makes it need to be a server script

1 Like

For example when a player touches a part the textlabel will only replicate to the client who touched the part (:arrow_backward: LOCAL SCRIPT). This is the reason I am using a server script.

That sounds like you’d want a LocalScript if you only want to replicate to one client.

3 Likes

No I was just explaining what happens if I use a local script. I do not want it to only replicate to only one client.

You probably want a LocalScript to do your GUI and a single server script (not one in every PlayerGui) to use a remote event with FireAllClients to tell them all to make the TextLabel.

2 Likes

Then, fire a BindableEvent to the Server that then fire a RemoteEvent to all Clients.

2 Likes

Something like this:

--The Serverscript parented to the Part
local Part = script.Parent
Part.Touched:Connect(function(hit:BasePart) --If the Part is touched
    if hit.Parent:FindFirstChildofClass("Humanoid") then --And it was touched from a player
        game.ReplicatedStorage.BindableEvent:Fire() --Then fire to the BindableEvent
    end
end)

--A ServerScript

game.ReplicatedStorage.BindableEvent.Event:Connect(function() --If the Part was touched from a player
    game.ReplicatedStorage.RemoteEvent:FireAllClients() --Then fire this RemoteEvent that says, that the Gui need to be showed up to all players
end)

--The LocalScript located in the StarterGui or a Gui

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
    local TextLabel = TheTextLabelLocation
    TextLabel.Text = "I am on"
end)

Hope this Code helps out, but yeah, you need a LocalScript, a serverscript is and will ever be a serverscript, so you can‘t get ANYTHING that is located on the Player

1 Like

Yeah I was thinking of something like that. Although the bindable event is unnecessary I will just put a script in serverscriptservice and send a remote event to the local script.

1 Like

In the part try some code like this:

db = true
script.Parent.Touched:connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") ~= nil then
        local player = game.Players:GetPlayerFromCharacter(part.Parent)
        if player ~= nil then
            if db == true then
                db = false
                --(I don't know how to use a for loop, please rewrite this part)
                for plr in game.Players do
                    label = Instance.New("TextLabel")
                    label.Text = "Hi"
                    label.Parent = player.PlayerGui.ScreenGui
                end
            end
      end
 end
 end)

I don’t know if this will work but it’s worth a try

for Variable1, Variable2 in ipairs() do --or pairs()
    --Something
end

And:

You can‘t really get PlayerOnly Objects (like PlayerMouse, Guis, etc) using this function, but you can get other things.