Im trying to look for difference instances throughout the player Gui, but I keep receiving errors that causes it to not work.
Error 1
Error:
12:06:52.466 Players.NubblyFry.PlayerGui.ScreenGui.CashMoney.Change:1: attempt to index nil with 'FindFirstChild' - Client - Change:1
12:06:52.467 Stack Begin - Studio
12:06:52.467 Script 'Players.NubblyFry.PlayerGui.ScreenGui.CashMoney.Change', Line 1 - Studio - Change:1
12:06:52.467 Stack End - Studio
Script:
local CashMoney = script.Parent.Parent.Parent:FindFirstChild("leaderstats"):FindFirstChild("Cash Money")
if CashMoney == script.Parent.Parent.Parent:FindFirstChild("leaderstats"):FindFirstChild("Cash Money") then
print("Successful")
else
error("Cash script was unsuccessful and erorred.")
end
function ScaleX()
for i = 1,4 do
task.wait(0.01)
script.Parent.Size = script.Parent.Size + UDim2.new(0.01, 0, 0, 0)
end
for i = 1,4 do
task.wait(0.01)
script.Parent.Size = script.Parent.Size - UDim2.new(0.01, 0, 0, 0)
end
end
function ScaleY()
for i = 1,2 do
task.wait(0.01)
script.Parent.Size = script.Parent.Size + UDim2.new(0, 0, 0.01, 0)
end
for i = 1,2 do
task.wait(0.01)
script.Parent.Size = script.Parent.Size - UDim2.new(0, 0, 0.01, 0)
end
end
CashMoney:GetPropertyChangedSignal("Value"):Connect(function(value)
if value then
script.Parent.Text = "Cash Money: "..tostring(value)
ScaleX()
ScaleY()
end
end)
Error 2
Error:
12:06:55.143 XP is not a valid member of TextLabel "Players.NubblyFry.PlayerGui.ScreenGui.TopBar.Level" - Server - XpDataStore:31
12:06:55.143 Stack Begin - Studio
12:06:55.143 Script 'ServerScriptService.XpDataStore', Line 31 - Studio - XpDataStore:31
12:06:55.143 Stack End - Studio
Script:
-- DataStore for XP
local DataStoreService = game:GetService("DataStoreService")
local RepStor = game:GetService("ReplicatedStorage")
local xpDataStore = DataStoreService:GetOrderedDataStore("xpDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats2 = Instance.new("Folder")
leaderstats2.Name = "leaderstats2"
leaderstats2.Parent = player
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats2
local XP = Instance.new("IntValue")
XP.Name = "XP"
XP.Parent = leaderstats2
local xpData
local levelData
local success, errormessage = pcall(function()
xpData = xpDataStore:GetAsync(player.UserId.. "-XP")
levelData = xpDataStore:GetAsync(player.UserId.. "-Level")
end)
if success then
player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").TopBar.Level.XP = xpData
player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").TopBar.Level.Level = levelData
else
print("There was an error whilest loading your data!")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
xpDataStore:SetAsync(player.UserId.."-XP", player.leaderstats2:FindFirstChild("XP").Value)
xpDataStore:SetAsync(player.UserId.."-Level", player.leaderstats2:FindFirstChild("Level").Value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error while saving data!")
warn(errormessage)
end
end)