Hey! I've got a problem when trying to run a PlayerAdded function in a Script. It works fine in Studio, but it simply doesn't fire the function in the real game.
Here's my code:
local DescenParent -- I put it here so I can access it from different functions
function PlayerAdded(plr)
print(1) --I made this to check if the function was fired
local WorkerDesk = script.Parent:GetDescendants()
local Scripts = plr:WaitForChild("Scripts"):WaitForChild("MScripts") --Gets the value of a stat i've done
wait(0.2)
for index, descendant in pairs(WorkerDesk) do
if descendant.Name == "Worker" and Scripts.Value < 1 then --Checks if the descendant is a Worker and if the value is less than 1
DescenParent = descendant.Parent --sets the DescenParent value to the current descendant parent, so I can return the model to that parent later
descendant.Parent = game.ServerStorage --moves the models to ServerStorage, making them invisible/untouchable
end
end
Scripts.Changed:Connect(function() --fires when the value is changed
for index, descendant in pairs(WorkerDesk) do
if descendant.Name == "Worker" and Scripts.Value > 0 then --checks if the descendant is a worker and if the player has more than one scripts
descendant.Parent = DescenParent --gives the models back to their last parent
end
end
end)
end
game.Players.PlayerAdded:Connect(PlayerAdded) --Calls the function
I'm going to explain what I want to do so it is easier for you to understand the code objectives.
It is a game based in Mario 64 where you have to collect Scripts (just like mario stars). This code should make a group of workers (Not NPCs, just models) appear in a specific place when the player has at least 1 script.
--game
--workspace
--Desks(folder)
--MScriptChecker(this script)
--RandomModel1
--RandomModel2
--Worker(model)
--Worker(model)
--players
--RandomPlayer1
--Scripts(folder)
--MScripts(NumValue)
I hope someone can help me with all the info I provided. I have been stuck so long in this code. I don't know why it doesn't fire any of the function. Thanks.

3 comments
You have no function called PlayerAdded. Instead you should do this :Connect(function(PlayerAdded) and put your script into the function
Never mind i say that you called the function know. The text was so tiny
you know instead of having to do -- on each line, you could just do --[[ --]]