✓ Accepted answer
You are attempting to index a RobloxLocked object, most likely the RobloxReplicatedStorage service.
You see, not all objects (including services) exist when the scripts are being executed. I ran this simple experiment in an empty baseplate, in studio:
game.ChildAdded:Connect(function(child)
local success, message = pcall(function()
print(child.ClassName)
end)
if not success then
warn(child, message)
end
end)
The output I got:
GamepadService
ControllerService
RobloxReplicatedStorage The current identity (2) cannot Class security check (lacking permission 5)
Things might be a little different in a real server but the problem most likely remains. To actually fix your issue, you need to figure out what is going on in your code and what you're trying to achieve. Why are you even listening to an event that fires when an object is added to the data model? You already have a PlayerAdded event listening to new players. You can listen to the CharacterAdded event of player to get a signal when their character spawns. Then simply move that character.
local function initializePlayerLeaderstats(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 1
stage.Parent = leaderstats
leaderstats.Parent = player
return leaderstats
end
local function teleportPlayer(player, cframe)
if player.Character then
player.Character:SetPrimaryPartCFrame(cframe)
end
end
local function getStat(player, name)
return player.leaderstats[name].Value
end
local function getPlayerCheckpoint(player)
local stage = getStat(player, "Stage")
local checkpoint = workspace.Checkpoints[tostring(stage)]
return checkpoint
end
local function handleNewPlayer(player)
initializePlayerLeaderstats(player)
local checkpoint = getPlayerCheckpoint(player)
teleportPlayer(player, checkpoint.CFrame + Vector3.new(0, 3, 0))
end
game.Players.PlayerAdded:Connect(handleNewPlayer)
5 comments
Which line does it specify?
also "workspace" is deprecated, use game.Workspace. and line 2, it's ClassName and the classname of a character would be model, not player.
Global Workspace is deprecated, not workspace.
Epuuc i didn't know it was depricated thanks though.
"Workspace" is deprecated, but "workspace" is not