Destorying a gui if userid is not creator

I want to make it so if you are not the creators you cant see the GUI, I created a script but it does not work. They are mutiple creators working on the game and I want to store the userids in a table.

There is nothing in output, it just wont work.

I have tried a module script, it did not work though.

local creatorsID = 
	{
		{}, {}, {4124017097}
	}

if game.Players.LocalPlayer.UserId ~= creatorsID then
	script.Parent:Destroy()
	return
end
2 Likes
local creatorsID = 
	{
		{}, {}, {4124017097}
	}

if table.find(creatorsID, game.Players.LocalPlayer.UserId) do
    print("Owner")
    else
    script.Parent:Destroy()
end

You were comparing a user’s id to the whole table instead of looking for the userid in the table.

1 Like

I dont think this would work, I tried and there is a error

1 Like

Try this instead:

local creatorsID = 
	{ 4124017097 }

if table.find(creatorsID, game.Players.LocalPlayer.UserId) then
	script.Parent:Destroy()
	return
end
1 Like

You should only clone it if they are a creator. This is just more code to run for no reason.

2 Likes

It’s important to understand that this only works because lua uses one based indexing. If this was another language, the first (0 index) creator wouldn’t be recognized with this same code.
[JS returns -1 if nothing is found in the equivalent function to fix this issue]

1 Like

I’m not sure I understand how other languages are relevant here.

1 Like

I can see there was having problem previous table in first. post. is it fixed? i already tested before

local creatorsID ={
	0,
	0,
	4124017097
}

print(creatorsID)

if table.find(creatorsID,game.Players.LocalPlayer.UserId) then
print("Owner")
else
script.Parent:Destroy()
end
1 Like

Is there a way to store the USERIDS in a module script.

2 Likes

Yes you can

LocalScript

local Module=require(game.ReplicatedStorage:WaitForChild('Module',9))

print(Module.CreatorId)

if table.find(Module.CreatorId,game.Players.LocalPlayer.UserId) then
	print("Owner")
else
	script:Destroy()
end

Module

local Module = {
CreatorId={
	0,
	0,
	4124017097,
};

}

return Module
3 Likes

You shouldn’t make it like this because it could get hacked easily. Instead, you should do something like this.

SERVER script in ServerScriptService

local ownerId = 1111111111

game.Players.PlayerAdded:Connect(function(player)
   if player.UserId == ownerId then
       Gui:Clone().Parent = player.PlayerGui
   end
end)
3 Likes

Serverside it’s actually yea more secure there small different. i dont think if hacker having very fast to modify before got deleted

Serverside ( module still same )

local Module=require(game.ReplicatedStorage:WaitForChild('Module',9))

print(Module.CreatorId)

game.Players.PlayerAdded:Connect(function(player)
if table.find(Module.CreatorId,player.UserId) then
print("Owner")
end end)
1 Like

It wasn’t specifically for you, but many people that do game development on Roblox will eventually move on to other platforms or other languages. Or maybe they came from another platform or use another language.

1 Like

This is unnecessary and in a well made and thought-out game, exploiters should only be able to see the UI but not abuse the functions behind it. If you have a kick event that isn’t secured its a matter of time before someone kicks everyone and ruins your game.

1 Like

If you want only certain userIds to see a gui, dont do it this way because if they find a way to disable the script before it has ran they can see it.
Instead place the GUI inside a script into server script service that checks everytime when a player joins if it’s in the user IDs table, then clone the GUI into the PlayerGui

1 Like

I’d say cloning would be better then destroying it if it’s a dev gui