Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script lacking permission cannot class security check?

I was trying to make a script that when a character was added in the game it would teleport it in a checkpoint but i kept getting an error i don't know what was wrong with the script.

Script :

game.ChildAdded:Connect(function(Character)
	if Character.className == "Player" then else return end
	local leaderstats = game.Players[Character.Name].leaderstats
	local stage = game.Players[Character.Name].leaderstats.Stage.Value
	Character.HumanoidRootPart.CFrame = workspace.Checkpoints[stage].CFrame + Vector3.new(0,3,0)
end)

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("IntValue")
	leaderstats.Name = "leaderstats"
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Value = 1
	leaderstats.Parent = player
	stage.Parent = leaderstats
end)

Output : `11:55:20.405 - The current identity (2) cannot Class security check (lacking permission 5)

5 comments

0

Which line does it specify?

0

also "workspace" is deprecated, use game.Workspace. and line 2, it's ClassName and the classname of a character would be model, not player.

0

Global Workspace is deprecated, not workspace.

0

Epuuc i didn't know it was depricated thanks though.

1

"Workspace" is deprecated, but "workspace" is not

1 answer

✓ 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)

This discussion is preserved as it was. New answers, comments, and votes are closed.