No error in the output strangely. The problem: My character’s face doesn’t change as it should, in my setUpAvatar function. Any help is appreciated, thank you.
Please see the script below.
local DS = game:GetService("DataStoreService")
local cashInterval = 10 -- in minutes
local cashGiveValue = 2 -- in Cash
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Cash"
cash.Value = 0
local startingCash = 0
local scope = "Player_"..player.UserId
local success, err = pcall(function()
local playerStats = DS:GetDataStore("PlayerStats"):GetAsync("Player_" .. player.UserId)
myCash = playerStats[1]
print("Player stats for "..player.Name.." retrieved.")
end)
if success then
cash.Value = myCash
print("Player stats for "..player.Name.." established.")
else
cash.Value = startingCash
print("Player stats for "..player.Name.." initiated.")
end
-- So the wallet is synced with the leaderstats value
player.Backpack:WaitForChild("Wallet"):FindFirstChild("Handle"):WaitForChild("BillboardGui"):WaitForChild("CashAmount").Text = "$"..player.leaderstats.Cash.Value
-- Gives the player cash every certain period
spawn(function()
while wait(cashInterval*60) do
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + cashGiveValue
end
end)
-- When the character loads
player.CharacterAdded:Connect(function(character)
setUpAvatar(character)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
print("Player ".. player.Name.. " is disconnecting.")
pcall(function()
DS:GetDataStore("PlayerStats"):SetAsync("Player_"..player.UserId, {player.leaderstats.Cash.Value})
print("Player stats for "..player.Name.." saving success.")
end)
end)
function setUpAvatar(character)
delay(1, function()
character:FindFirstChild("Head").face.Texture = "rbxassetid://34067417"
--character:WaitForChild("Head"):WaitForChild("face"):Destroy()
-- local face = Instance.new("Decal", character.Head)
-- face.Texture = "rbxassetid://34067417"
end)
end