This script was working a few hours ago but now it suddenly won’t print “Added” .
game.Players.PlayerAdded:Connect(function(player)
local PayWalls = Instance.new("Folder")
PayWalls.Parent = player
PayWalls.Name = "PayWalls"
for i, v in pairs(payWallsFolder:GetChildren())do
local wallObject = Instance.new("ObjectValue")
wallObject.Parent = PayWalls
wallObject.Value = v
wallObject.Name = v.Name
local access = Instance.new("BoolValue")
access.Parent = wallObject
access.Name = "Access"
local value = payWallStore:GetAsync(player.UserId.."-"..wallObject.Name)
print(value)
access.Value = payWallStore:GetAsync(player.UserId.."-"..wallObject.Name)
end
player.CharacterAdded:Connect(function(char)
print("Added")
for i, v in pairs(PayWalls:GetDescendants()) do
if v.Value == true then
print("Has Been Added")
local collisionGroup = v.Parent.Name
print(collisionGroup)
addCharacterToCollisionGroup(char,collisionGroup)
end
end
end)
end)
The data store is working and all however my player.CharacterAdded event won’t even print “Added”. What happened? I’m sure it’s enabled.
local function onPlayerAdded(player)
local PayWalls = Instance.new("Folder")
PayWalls.Parent = player
PayWalls.Name = "PayWalls"
for i, v in pairs(payWallsFolder:GetChildren())do
local wallObject = Instance.new("ObjectValue")
wallObject.Parent = PayWalls
wallObject.Value = v
wallObject.Name = v.Name
local access = Instance.new("BoolValue")
access.Parent = wallObject
access.Name = "Access"
local value = payWallStore:GetAsync(player.UserId.."-"..wallObject.Name)
print(value)
access.Value = payWallStore:GetAsync(player.UserId.."-"..wallObject.Name)
end
player.CharacterAdded:Connect(function(char)
print("Added")
for i, v in pairs(PayWalls:GetDescendants()) do
if v.Value == true then
print("Has Been Added")
local collisionGroup = v.Parent.Name
print(collisionGroup)
addCharacterToCollisionGroup(char,collisionGroup)
end
end
end)
end
for i, player in ipairs(game.Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
The character may already be present when event is connected, which means your function is never called. The way you fix this is by giving the function a name and calling it if the character is already present.
game.Players.PlayerAdded:Connect(function (player)
local function onCharacter(char)
print("Character found!", char:GetFullName())
-- ...
end
player.CharacterAdded:Connect(onCharacter)
-- If the character is already present, we need to manually call onCharacter.
if player.Character then
-- Using task.spawn here ensures that code after this
-- call won't be blocked if onCharacter yields.
task.spawn(onCharacter, player)
end
end)
If you figured out your problem, you should post about it in your own thread in case someone else has a similar problem. Marking your own “I figured it out” post as a solution is counterproductive unless you’ve actually shown a solution.