I forgot how to make a gui that only the creator can see.
Can anybody help me?
Well I suggest doing some research on the API, but you just check when a player is added for their playerid. If it is not the same as what is required to see the gui the just end.
Make a script in ServerScriptService, and paste the following code into it.
local GUIName = "ScreenGui"
function PlayerAdded(plr)
if plr.UserId == game.CreatorId then
script:FindFirstChild(GUIName):Clone().Parent = plr:WaitForChild("PlayerGui")
end
end
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
PlayerAdded(v)
end
game:GetService("Players").PlayerAdded:Connect(PlayerAdded)
Change GUIName to the name of you GUI, and parent the GUI to the script you added.
LocalScript or Script?
Script in serverscriptservice
I will try. So, I guess my problem is solved
Mark it as the solution please.
Ok. I forgot to to do that.
You can actually shorten that code by a lot.
Put this inside a LocalScript inside the ScreenGui.
game.Players.LocalPlayer.CharacterAdded:Connect(function()
if game.Players.LocalPlayer.UserId ~= game.CreatorId then
script.Parent:Destroy() -- destroy it for extra security
end
end)
The gui will still replicate to the client, some bad actor might be able to fake the gui and scam some users saying they are the owner.
It’s honestly just better to do this and on the server.
local Players = game:GetService("Players")
local Gui = script.Parent #-- Gui under game.ServerScriptService, server-script under the Gui since LocalScript objects only run under certain containers
local function onPlayerAdded(player)
if player.UserId == "[Creator's User Id]" then #-- if the player's user id equals a predefined id
local PGui = player:WaitForChild("PlayerGui", 10) # wait fo the PlayerGui container to exist
Gui:Clone().Parent = PGui #-- clone the Gui, and set the Parent property
end
end
Players.PlayerAdded:Connect(onPlayerAdded) #-- pass the callback to the listener
Lua code syntax highlighting also needs to work better, comments not being formatted normally.
I believe you could do something like this in a localscript as well!
Let’s not forget clients have full control of their system, so it’d be less secure doing it all client-side.
True, but if the GUI’s functionalities are only going to affect the client it may not matter as much.
True, but only if that is the case
and it isn’t providing any sort of benefit to an extent where hiding it would be necessary (at that point it’d be better to not hide it at all) .
Use local script or maybe just if player id and = and put id in
Use the get function and lock it to to id or the creator