Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Bug With Custom Character Shirt Color Saving For Server?

I'm Trying To Make A Script To Change The Shirt Color Of A Custom Character And Make It Save For That Server, But I Just Can't Seem To Get It Working. It's A Normal Server Script Located In ServerScriptService. It Doesn't Make Any Errors Of Any Kind Or Even Do Anything In General. I Just Can't Figure It Out. ;-;

B = {}
C = {}
game.Players.PlayerAdded:Connect(function(A)
    table.insert(B,#B,Color3.fromRGB(math.random(1,255),math.random(1,255),math.random(1,255)))
    table.insert(C,#C,A.Name)
end)
while wait(0.0000001) do
    for i=1,#C do
	    Character = game.Workspace:FindFirstChild(C[i])
	    Character.Torso0.Color = B[i]
    end
end

EDIT: I Got It Kinda Working But It Won't Stay When I Die.

B = {}
C = {}
game.Players.PlayerAdded:Connect(function(A)
	table.insert(B,#B+1,Color3.fromRGB(math.random(1,255),math.random(1,255),math.random(1,255)))
	table.insert(C,#C+1,A.Name)
end)
while wait(0.0000001) do
	for i=1,#C do
		local Character = game.Workspace:FindFirstChild(C[i])
		Character.Torso0.Color = B[i]
	end
end

1 comment

0

try adding a .died event and putting that for loop in it

1 answer

It wont stay when you die because when you die it resets your character's clothes and everything like that so...

I'd say your best bet is a localscript in the character humanoid that hooks to a remote event on the server, something like this:

LOCAL SCRIPT (Put this inside of StarterCharacterScripts)

repeat wait(0.2) until game.Players:GetPlayerFromCharacter(script.Parent)~=nil and script.Parent:FindFirstChild("Torso")~=nil
game.ReplicatedStorage.RemoteEvent:FireServer(script.Parent)

Server Script (Put this in ServerScriptService)

local color= Color3.fromRGB(1,2,3) --whatever you're going to put here.
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,character)
	character.Torso.Color=color
end)

Then, just create a RemoteEvent in ReplicatedStorage. Bam! It even works every time you die.

This discussion is preserved as it was. New answers, comments, and votes are closed.