I changed the the variable UserInterface to :WaitForChild but says infinite yield and just doesnt work, but when i try in roblox studio it works
local DataStoreService = game:GetService("DataStoreService")
local TierDataStore = DataStoreService:GetDataStore('TierDataStore')
local StrengthDataStore = DataStoreService:GetDataStore('StrengthDataStore')
local DefenseDataStore = DataStoreService:GetDataStore('DefenseDataStore')
local CoinsDataStore = DataStoreService:GetDataStore('CoinsDataStore')
local HealthMaxDataStore = DataStoreService:GetDataStore('HealthMaxDataStore')
local ExperienceDataStore = DataStoreService:GetDataStore('ExperienceDataStore')
local ExpNeededDataStore = DataStoreService:GetDataStore('ExpNeededDataStore')
local Stats = game.ReplicatedStorage.Media.Stats:Clone()
local StarterGui = game:GetService('StarterGui')
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
wait(2)
local UserInterface = player.PlayerGui.UserInterface
Stats.Parent = player
Stats.Tier.Value = TierDataStore:GetAsync(player.UserId) or 1
Stats.Strength.Value = StrengthDataStore:GetAsync(player.UserId) or 1
Stats.Defense.Value = DefenseDataStore:GetAsync(player.UserId) or 1
Stats.Coins.Value = CoinsDataStore:GetAsync(player.UserId) or 100
Stats.HealthMax.Value = HealthMaxDataStore:GetAsync(player.UserId) or 100
Stats.Experience.Value = ExperienceDataStore:GetAsync(player.UserId) or 0
Stats.ExpNeeded.Value = ExpNeededDataStore:GetAsync(player.UserId) or 1000
Stats.Tier.Changed:Connect(function()
Stats.Tier.Value = TierDataStore:SetAsync(player.UserId, Stats.Tier.Value)
print('saved')
end)
Stats.Strength.Changed:Connect(function()
Stats.Strength.Value = StrengthDataStore:SetAsync(player.UserId, Stats.Strength.Value)
print('saved')
end)
Stats.Defense.Changed:Connect(function()
Stats.Defense.Value = DefenseDataStore:SetAsync(player.UserId, Stats.Defense.Value)
print('saved')
end)
Stats.Coins.Changed:Connect(function()
Stats.Coins.Value = CoinsDataStore:SetAsync(player.UserId, Stats.Coins.Value)
print('saved')
end)
Stats.HealthMax.Changed:Connect(function()
Stats.HealthMax.Value = HealthMaxDataStore:SetAsync(player.UserId, Stats.HealthMax.Value)
print('saved')
end)
Stats.Experience.Changed:Connect(function()
Stats.Experience.Value = ExperienceDataStore:SetAsync(player.UserId, Stats.Experience.Value)
print('saved')
end)
Stats.ExpNeeded.Changed:Connect(function()
Stats.ExpNeeded.Value = ExpNeededDataStore:SetAsync(player.UserId, Stats.ExpNeeded.Value)
print('saved')
end)
char.Humanoid.Health = Stats.HealthMax.Value
UserInterface.TierFrame.Tier.Text = 'Tier: '..Stats.Tier.Value
player.PlayerGui:SetTopbarTransparency(1)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health , false)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
UserInterface.TextLabel.Text = 'Coins:'..Stats.Coins.Value
char.Humanoid.HealthChanged:Connect(function()
player.PlayerGui.UserInterface.HealthBar.Frame:TweenSize(UDim2.new(char.Humanoid.Health/100, 0, 1, 0),'Out', 'Quad', 0.01, false)
end)
local tag = game.ServerStorage.BillboardGui:Clone()
tag.Parent = char.Head
tag.TextLabel.Text = player.Name
if player.Name == 'Sage_Prodigy' then
tag.TextLabel.Text = 'Owner'
tag.TextLabel.TextColor3 = Color3.fromRGB(255,237,35)
end
end)
end)
