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

Making a script where player gets a random face when they join, but it wont work?

The way my system works is I made a table full of face ids, and then when the player joins I check for character added. When the character is added I randomize threw the table, and change the characters face id. Then I change the datastore value to the id picked, to save the face. But if the player had a face id already I just load the id in threw the value of the string.

Check bottom of script for issue

local faces = {
	7074882,
	33082306,
	46997764,
	34973033,
	28009686,
	48203113,
	23931977,
}

local Players = game:GetService("Players")		

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)		
		local name = player.Name
		
		if player:WaitForChild("stats").face.Value == "nil"  then		
			local Chosen = faces[math.random(1, #faces)]
			print(Chosen)
			char.Head.face.Texture = "rbxassetid://"..Chosen
			player:WaitForChild("stats").face.Value = Chosen
		end
	end)
end)

The system doesn't print anything for Chosen though it should, and the "rbxassetid://" changes but the id won't go into the texture. Why?

1 comment

0

Maybe try not putting the "rbxassetid://" before that. I once changed the texture just with the ID.

1 answer

You are checking to see if the value of the face is "nil", which I assume you meant by nil. However, the default value for a StringValue is neither "nil" nor nil. It is simply "".

The way you could fix this is by doing this:

if player:WaitForChild("stats").face.Value == ""  then 

2 comments

0

No I meant nil. I changed it to "nil" not nil as in nothing.

0

would that cause any issues?

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