How do i make it so when a certain user like me joins a game a script will automatically run

i need my rainbow text script to run automatically whenever i join the game so i can have a rainbowtext as my username color

thanks alot

Hi there. I’d recommend using the code below as a reference to build upon and adjust to your needs or to integrate it inside of your existing nametags script.

The comments in the code should be sufficient to understand the usability and execution.

-- ServerScript

local Players = game:GetService("Players") -- Get the "Players" Service

local playerIds = {1779037009, 22222, 333333, 444444} -- Array containing all the UserIds of specific players you'd like to detect. 

Players.PlayerAdded:Connect(function(plr)
	-- Check if the connecting player's ID matches any IDs from the preset playerIds table.
	if table.find(playerIds, plr.UserId) then
		-- Execute a certain code
	end
end)
2 Likes

it worked! thank you for already using my id in the script :rofl: and thank you for helping me.

2 Likes

hi again, sorry to bother but is there a way to make this local so only 1 client sees it. if its possible thanks

Don’t worry, not a bother at all. Just to understand what you’re asking for a bit better, do you mean having this behavior but only for the specific client if the client is one of the UserIds mentioned in the playerIds table?

If so, something along the lines of the code below should be a good starting point to further develop or amend to match your needs.

-- LocalScript

local Players = game:GetService("Players")
local plr = Players.LocalPlayer

local playerIds = {1779037009, 22222, 333333, 444444}

task.wait(1)

if table.find(playerIds, plr.UserId) then
	-- Execute a certain code if the client has one of the UserIds in playerIds
end

The code above checks if the connected client has one of the UserIds in the playerIds table and executes any code locally if so. Implementing this correctly would depend on what you’re using it for and if the code needs to be ran only once, or multiple times whenever the player resets (considering your use case of nametags).

Hope this helps. Don’t hesitate to let me know if this wasn’t what you meant.

1 Like

it worked! im not sure if its client sided though

SSS or ServerScriptService, as the name suggests, is an ideal service that holds server sided scripts.

Considering you’re trying to perform a certain action only on the client, the code above would need to be used in a LocalScript instead.

For LocalScripts, an ideal place for them would be StarterPlayerScripts inside of StarterPlayer or depending on your use case.

Ok so the script you made works an all but my script doesnt could you help heres the idea:

so i want to make a perma ban system for people that have hacked or for any reason in general hard wired inside the game (not a data store) thats why i need the client side script so my script can run whenever the hacker joins and will freeze, blur, and then show a gui saying your banned. could you help make a script that does all of those but works with the script you made previously? Thank you so much for your help.

Gotcha, thanks for the elaboration.

For the permanent ban system and the consequences to being banned, you will need to utilize Roblox DataStores for handling and storing all pbanned players. For the rest of the consequences, most of which will need to be handled on the client, which will require you to get accustomed to using RemoteEvents.

There are loads of tutorials on this that can help you get a headstart on such system that you access with a simple search here on the DevForums, Google, or YouTube. Other than that, if you run into any specific issues during this process that you get stuck on, you’re always welcome to create a new post in this section.

Is there any way I can hire u as a programmer? I can pay in robux :joy: :joy: I’m not really good at scripting nor do I have time to learn (sorry for being blunt). Thank you anyways for all the help that you have already given me!

1 Like

I understand, and I unfortunately do not have the time to commit to any additional projects either, but a quick search on the Roblox TalentHub (alongside many other resources) should land you with countless options and creators who may be readily available for this. Other than that, if you have the time, I always encourage learning basic scripting as it helps give you a much better control and understanding of what and how your game functions.

Regardless, I wish you the best.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.