How do I make a function occur when a player is added to the game locally?

Can someone help me fix my problem? I’m trying to make a coloring change to 12 parts locally (basically different to each player). Can someone send me a script that fixes the code mentioned later, and if you want you can help me clean up the code.

Thanks :smiley:

1 Like

You could create a new LocalScript and store it in StarterPlayerScripts, that should essentially do the same thing here, except it would run locally.

1 Like

Thanks! I’ll try that!

mustbe30chars

I tried that, but it didn’t work, is there anything I have to change?

Make a local partcolor and try to use the Player.PlayerAdded:Connect(function(-your function-)
-your function-- give it a single color using
local partColor = game.Workspace.Part.BrickColor.(choose your color)
and try to fire the event when player is added
or try to use True or False functions in your function
I’m also currently working to solve your problem try these methods as i said

Just a cleaner version of @DentinDev’s response:

game.Players.PlayerAdded:Connect(function()
    -- put the variables & colouring stuff here
end)

This should work.

1 Like

Just a question, but is this supposed to be in a local script or a normal one?

Normal script

character limit thingy ignore this

Also does it work locally (basically, just for a certain player but different for another if having a randomizer)? and do I need parameters?

If it’s in a serverscript the changes appear for everyone. To do this locally, use a LocalScript.

Set its parent as StarterPlayer.StarterPlayerScripts then just put the code inside your event in the script; you won’t need the event in the LocalScript as it’s only going to run once on player join.

LocalScripts cannot run in workspace, so do not make the mistake of putting it there.

e.g.

local model = workspace.Model
local part1 = model.Part1
-- obviously use your paths, just an example of how you'll need to switch your defining
part.BrickColor = BrickColor.new("Really red")

This will switch the colours ONLY for the person who joined.

1 Like

I will try this! mustbe30chars

like this?

That should work, yeah. Sorry for the slow response, didn’t get the popup notif

1 Like