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

Cloning decal into a player's head on spawn problem..?

Asked by
RoyMer 301 Moderation Voter
8 years ago

What is wrong with clone face to the player's Head on spawn? It works good in Roblox Studio but not in game??

It is a local script and is in the StarterGui

local player = game.Players.LocalPlayer
save = player.FaceSave.Value

player.CharacterAdded:connect(function(character)
local clone = game.Lighting.Faces:FindFirstChild(save):Clone()
clone.Parent = player.Character.Head
wait(2)
for i,v in pairs(character.Head:GetChildren()) do
if v.ClassName == "Decal" and v.Name ~= save then
v:Destroy()
end
end
end)

1 answer

Log in to vote
0
Answered by 8 years ago

This happens because local scripts run much faster then normal so it runs before the character is created. To fix put

repeat wait(.1) until player.Character

At the first line of the script and it should work disregarding any errors in the script itself.

Ad

Answer this question