Inside a touched event, I have this code:
Door.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player.HiddenStats.HasTycoon == false then
-- DO SOMETHING
end
end)
The output is saying attempt to index nil with HiddenStats. But if I print Player, it shows me my player's name properly. Why can't it get the HiddenStats of the Player?
But however, if I say if Player then -- Code here end
It runs in the else block. Which means that there is no player. The script is not running if Player then part.
I have no idea why.
This is the leaderboard script (I have added the player added event properly but not shown here):
local HiddenStats = Instance.new("Folder", Player)
HiddenStats.Name = "HiddenStats"
local HasTycoon = Instance.new("BoolValue", HiddenStats)
HasTycoon.Name = "HasTycoon"
HasTycoon.Value = false
Why is it showing such error?
Thanks for any help

3 comments
Are both of the scripts in a server script (not local script) and inserted in SSS (ServerScriptStorage)?
The leaderboard script inside the serverscriptserver. And the other one is inside a part in workspace
Both are normal scripts. They are not local script