I cant figure out how to make only 1 player change colors instead of 2

I wrote this peice of code that changed the players bodycolor when they press a button.
When you press it. everyone changes there bodycolor to the color the player pressed.
I dont know how to make it so only 1 player changes color and the others dont.

Main Code:

LoadEvent.OnServerEvent:Connect(function(PlrID, R,G,B)
	PlrColors.HeadColor3 = Color3.fromRGB(R,G,B)
	PlrColors.LeftArmColor3 = Color3.fromRGB(R,G,B)
	PlrColors.LeftLegColor3 = Color3.fromRGB(R,G,B)
	PlrColors.RightArmColor3 = Color3.fromRGB(R,G,B)
	PlrColors.RightLegColor3 = Color3.fromRGB(R,G,B)
	PlrColors.TorsoColor3 = Color3.fromRGB(R,G,B)
end)

Activation Code:

local BodyColor = game.ReplicatedStorage.CharacterColors.Red["Body Colors"].HeadColor3 --Depending on the button i will change this.
local Plr = game.Players.LocalPlayer
local PlrID = game.Players.LocalPlayer.UserId
local NewBodyColor = {BodyColor.R,BodyColor.B,BodyColor.G}
local ColorSaver = game.ReplicatedStorage.SaveColors
local ColorLoader = game.ReplicatedStorage.LoadColors

script.Parent.MouseButton1Click:Connect(function()
	ColorSaver:FireServer(Plr,PlrID, BodyColor.R, BodyColor.G, BodyColor.B)
	wait(0.1)
	ColorLoader:FireServer(Plr,PlrID, BodyColor.R, BodyColor.G, BodyColor.B)
end)

What is PlrColors in this code?

local LoadEvent = game.ReplicatedStorage.LoadColors
local Char = script.Parent
wait(0.01)
local HRP = Char:FindFirstChildWhichIsA(“Humanoid”)
local PlrColors = Char:FindFirstChildWhichIsA(“BodyColors”)
local Data = game:GetService(“DataStoreService”):GetDataStore(“PlayerColor”)
local PlayerIdFetcher = game.ReplicatedStorage.PlayerID
local PlrID = game.Players:GetPlayerFromCharacter(Char)
– This code is inside StarterCharacterScripts

If you’re changing the bodycolors of the starter character in starterplayer then everytime a player’s character spawns they will have the bodycolors to what they were set to last. Why don’t you just set the bodycolors directly using PlayerID?

When the player dies they will keep the color becuase im saving it in a datasore

--ServerScriptService
local DataStore = game:GetService("DataStoreService")
local Data = DataStore:GetDataStore("PlayerColor")


game.ReplicatedStorage.SaveColors.OnServerEvent:Connect(function(plr ,ID, a,R,G,B)
	local Table = {R,G,B}
	print(Table)
	Data:SetAsync(ID, Table)
end)

Thats kind of the whole point

Fixed it:
Get the player (not local)
Check if the playerID is equal to the player
If its true, Runs the code

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