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

How would I constantly give the character a stringvalue?

At the moment I have a script that gives a player a stringvalue called "CurrentRace" (which decides their race). But at the moment if they die with the current race stringvalue they lose their race, how would I make it so the currentrace automatically replicates into the new character?

-- ev 3/2/2021
Players.PlayerAdded:Connect(function(player)
	repeat
		wait()
	until
	player.Character

	local chosenRace = races[math.random(1,#races)]
	player.Character:WaitForChild("CurrentRace").Value = chosenRace
	if chosenRace == "Forturs" then
		local roll2 = math.random(1,2)
		if roll2 == 1 then
		local colour = Color3.fromRGB(170, 0, 0) -- fill this RGB value in
		local bodyColours = player.Character:WaitForChild("Body Colors")
		bodyColours.HeadColor3 = colour
		bodyColours.LeftArmColor3 = colour
		bodyColours.RightArmColor3 = colour
		bodyColours.LeftLegColor3 = colour
		bodyColours.RightLegColor3 = colour
		bodyColours.TorsoColor3 = colour
		end
		if roll2 == 2 then
			local colour = Color3.fromRGB(0, 170, 0) -- fill this RGB value in
			local bodyColours = player.Character:WaitForChild("Body Colors")
			bodyColours.HeadColor3 = colour
			bodyColours.LeftArmColor3 = colour
			bodyColours.RightArmColor3 = colour
			bodyColours.LeftLegColor3 = colour
			bodyColours.RightLegColor3 = colour
			bodyColours.TorsoColor3 = colour
		end
	else
		if chosenRace == "Hahns" then
			local colour = Color3.fromRGB(0, 85, 255) -- fill this RGB value in
			local bodyColours = player.Character:WaitForChild("Body Colors")
			bodyColours.HeadColor3 = colour
			bodyColours.LeftArmColor3 = colour
			bodyColours.RightArmColor3 = colour
			bodyColours.LeftLegColor3 = colour
			bodyColours.RightLegColor3 = colour
			bodyColours.TorsoColor3 = colour
			local clone = game.ServerStorage.Barbarity
			clone.Parent = player.Character
		else
			if chosenRace == "Yitals" then
				local colour = Color3.fromRGB(248, 255, 201) -- fill this RGB value in
				local bodyColours = player.Character:WaitForChild("Body Colors")
				bodyColours.HeadColor3 = colour
				bodyColours.LeftArmColor3 = colour
				bodyColours.RightArmColor3 = colour
				bodyColours.LeftLegColor3 = colour
				bodyColours.RightLegColor3 = colour
				bodyColours.TorsoColor3 = colour
			else
				if chosenRace == "Pardeos" then
					local colour = Color3.fromRGB(255, 255, 255) -- fill this RGB value in
					local bodyColours = player.Character:WaitForChild("Body Colors")
					bodyColours.HeadColor3 = colour
					bodyColours.LeftArmColor3 = colour
					bodyColours.RightArmColor3 = colour
					bodyColours.LeftLegColor3 = colour
					bodyColours.RightLegColor3 = colour
					bodyColours.TorsoColor3 = colour
				end
			end
		end
	end
end)

1 answer

✓ Accepted answer

First, you haven't :Clone()'d the "clone" variable, also, you could just place the StringValue inside of StarterCharacter, as everything under StarterCharacter gets automatically placed inside of a players character.

6 comments

0

It works, thanks for the improvement! But now the race resets upon dying, (CurrentRace still clones but it resets the race back to Raceless)

0

I updated the post with the rolling script. it's very messy but where would i be able to make it so based on their chosenrace it would stay even if they died?

0

You could also just parent it under player, which would require PlayerAdded. Anytime they reset it won't go away

0

It works, but the skin tone is removed, how would I keep the skin tone when it resets (your suggestion did work so I'll accept the answer) but this is just a secondary question.

0

You can always save it to a table, too

0

What do you mean by that? Do you mean store the RGB colors into a table, if so how would I do that and how would it save it upon the character dying?

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