Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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?

0
Maybe try not putting the "rbxassetid://" before that. I once changed the texture just with the ID. FireSam5163 22 — 3y

1 answer

Log in to vote
0
Answered by
Raccoonyz 1092 Donator Moderation Voter
3 years ago

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 
0
No I meant nil. I changed it to "nil" not nil as in nothing. XxWingKing 96 — 3y
0
would that cause any issues? XxWingKing 96 — 3y
Ad

Answer this question