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

Random Face on Death?

Asked by 7 years ago

I'm currently developing a group place but I have no idea on how to generate random faces (or decals). I have around 10 custom made faces I made specifically for that reason. I only know how to script a single face that appears on death... Can anyone help? Thanks!

I asked for help on the ROBLOX Forums and they ended up with this. Script that didn't work:

local ContentProvider = game:GetService("ContentProvider")
repeat wait() until game.Players.LocalPlayer.Character ~= nil
repeat wait() until (ContentProvider.RequestQueueSize == 0)

local Plr = game.Players.LocalPlayer
local Char = game.Players.LocalPlayer.Character
while true do
    wait(0.1)
    if script.Parent.Humanoid ~= nil then
        if script.Parent.Humanoid.Health ==1 then
local ChangeFace = true
local FaceId = {574701104, 574701264, 574701296, 574701328, 574701359, 574701387, 574701414, 574701431, 574701479, 574701532}

wait(0.5)

if ChangeFace then
local var = FaceId[math.random(1,10)]'FaceId'

Char:WaitForChild("Head").face.Texture = ("http://www.roblox.com/asset/?id=" .. var)
end
wait(0.1)
            script:remove()
        end
    end
end

0
This is over complicating a very simple thing. User#5423 17 — 7y
0
Whoever decided to downvote me, boo you. You must not know a thing about how to use math.random(). As I was saying, line 17, remove 'FaceId' at the end. That's just a bug. Shawnyg 4330 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
local ContentProvider = game:GetService("ContentProvider")
repeat wait() until game.Players.LocalPlayer.Character ~= nil
repeat wait() until (ContentProvider.RequestQueueSize == 0)

local Plr = game.Players.LocalPlayer
local Char = game.Players.LocalPlayer.Character
while true do
    wait(0.1)
    if script.Parent.Humanoid ~= nil then
        if script.Parent.Humanoid.Health ==1 then
local ChangeFace = true
local FaceId = {574701104, 574701264, 574701296, 574701328, 574701359, 574701387, 574701414, 574701431, 574701479, 574701532}

wait(0.5)

if ChangeFace then
local var = FaceId[math.random(1,#FaceId)] --#FaceId is the number of values in the table, so you don't have to continuously update the value

Char:WaitForChild("Head").face.Texture = ("http://www.roblox.com/asset/?id=" .. var)
end
wait(0.1)
            script:remove()
        end
    end
end

So what I did was remove 'FaceId' at the end of line 17, because it causes an error. Also instead of putting (1, 10) on line 17, you can put (1, #FaceId). #FaceId is the number of all the children inside of the table.

Hope this has helped!

0
I tried it, it doesn't do anything :( Aurified 12 — 7y
0
Maybe because of line 10? It only runs if the player's health is 1 thehybrid576 294 — 7y
0
I changed it... It didn't work. Is there a specific place I have to put the script? Aurified 12 — 7y
0
is this a localscript or a serverscript? thehybrid576 294 — 7y
Ad

Answer this question