My PlayerAdded function for some reason does not run, it did run a few moments ago but now it suddenly just stopped.
Does not print anything in the output.
local Parent = script.Parent
local Aureus = game:GetService("ServerScriptService").Values.Number:WaitForChild("Aureus")
-- Bank
local BankPage = Parent:WaitForChild("Page")
local AmountDisplay = BankPage:WaitForChild("AmountDisplay")
local IDText = BankPage:WaitForChild("ID")
local UserText = BankPage:WaitForChild("User")
------ Function ------
game.Players.PlayerAdded:Connect(function(plr) --- Does Not Fire
print(plr)
end)
-- Parent/Other
local Parent = script.Parent
local Aureus = game:GetService("ServerScriptService").Values.Number:WaitForChild("Aureus")
-- Bank
local BankPage = Parent:WaitForChild("Page")
local AmountDisplay = BankPage:WaitForChild("AmountDisplay")
local IDText = BankPage:WaitForChild("ID")
local UserText = BankPage:WaitForChild("User")
------ Function ------
game.Players.PlayerAdded:Connect(function(plr)
print(AmountDisplay.Text)
print(Aureus.Value)
AmountDisplay.Text = Aureus.Value
UserText.Text = plr.Name
IDText.Text = "ID "..tostring(plr.UserId)
end)
Aureus.Changed:Connect(function()
local roundDecimals = function(num, places) --num is your number or value and places is number of decimal places, in your case you would need 2
places = math.pow(10, places or 0)
num = num * places
if num >= 0 then
num = math.floor(num + 0.5)
else
num = math.ceil(num - 0.5)
end
return num / places
end
Aureus.Value = roundDecimals(Aureus.Value, 2)
AmountDisplay.Text = Aureus.Value
end)
if you join on a second account a few moments after you join on your original account, does the PlayerAdded event fire? It may be because the player is joining to quickly, and the WaitForChild things may yield the script a bit
Seems to be this line since when I remove it, the PlayerAdded function runs but not when I remove the “Bank” waitforchild. Anyway to combat this issue?
local Aureus = game.ServerScriptService.Values.Number:WaitForChild("Aureus")
local Parent = script.Parent
local Aureus = game:GetService("ServerScriptService").Values.Number:WaitForChild("Aureus")
-- Bank
local BankPage = Parent:WaitForChild("Page")
local AmountDisplay = BankPage:WaitForChild("AmountDisplay")
local IDText = BankPage:WaitForChild("ID")
local UserText = BankPage:WaitForChild("User")
------ Function ------
function playerAdded(plr)
print("player joined")
end
-- scan for existing players
for _, plr in next, game.Players:getPlayers() do
playerAdded(plr)
end
game.Players.PlayerAdded:Connect(playerAdded)
Given that you need the value of Aureus to process the PlayerAdded thing, reorganising it isn’t really an option. What you can do is have everything as it is, but loop through any players that are already in the game by the time the PlayerAdded connection is made!
-- Parent/Other
local Parent = script.Parent
local Aureus = game:GetService("ServerScriptService").Values.Number:WaitForChild("Aureus")
-- Bank
local BankPage = Parent:WaitForChild("Page")
local AmountDisplay = BankPage:WaitForChild("AmountDisplay")
local IDText = BankPage:WaitForChild("ID")
local UserText = BankPage:WaitForChild("User")
------ Function ------
local function PlayerAdded(plr)
print(AmountDisplay.Text)
print(Aureus.Value)
AmountDisplay.Text = Aureus.Value
UserText.Text = plr.Name
IDText.Text = "ID "..tostring(plr.UserId)
end
for _, plr in ipairs(game.Players:GetPlayers()) do
PlayerAdded(plr)
end
game.Players.PlayerAdded:Connect(PlayerAdded)
Aureus.Changed:Connect(function()
local roundDecimals = function(num, places) --num is your number or value and places is number of decimal places, in your case you would need 2
places = math.pow(10, places or 0)
num = num * places
if num >= 0 then
num = math.floor(num + 0.5)
else
num = math.ceil(num - 0.5)
end
return num / places
end
Aureus.Value = roundDecimals(Aureus.Value, 2)
AmountDisplay.Text = Aureus.Value
end)