Greetings, I just encountered the most misleading bug that I cannot fix at all…
My Player is not getting detected for some reason…
for _, KeyCheckpoint in pairs(Checkpoints:GetChildren()) do
KeyCheckpoint.Touched:Connect(function(CharacterPart)
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
-- Anything after here does not run. Determined with print()
local Player: Player = Players:GetPlayerFromCharacter(CharacterPart.Parent)
if KeyCheckpoint.Name ~= "EndRace" then
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
SetCheckpoint(Player, KeyCheckpoint, true)
end
else
if not Player:GetAttribute("PlayerCompleted") then
local Valid: boolean = true
for AttributeName, AttributeValue in pairs(Player.KeyCheckpoints:GetAttributes()) do
if not AttributeValue then
Valid = false
end
end
if Valid then
if BloxyKartService.Gamemode ~= "FreeRoam" then
if Player:GetAttribute("LapNumber") == MapLaps then
CompletedRace(Player)
else
CompletedLap(Player)
end
end
end
end
end
end
end)
end
What is REALLY misleading is that this system worked normally before… No changes to the script…
If you see nothing wrong with the script and you have experience, please let me know
I am not ready to announce that I am delaying a Live Event tomorrow due to a bug that just started happening for no reason…
If you can help, that would be great.
Thanks in advance.
1 Like
Try this?
for _, KeyCheckpoint in pairs(Checkpoints:GetChildren()) do
KeyCheckpoint.Touched:Connect(function(CharacterPart)
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
local Player = Players:GetPlayerFromCharacter(CharacterPart.Parent)
if KeyCheckpoint.Name ~= "EndRace" then
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
SetCheckpoint(Player, KeyCheckpoint, true)
end
else
if not Player:GetAttribute("PlayerCompleted") then
local Valid: boolean = true
for AttributeName, AttributeValue in pairs(Player.KeyCheckpoints:GetAttributes()) do
if not AttributeValue then
Valid = false
end
end
if Valid then
if BloxyKartService.Gamemode ~= "FreeRoam" then
if Player:GetAttribute("LapNumber") == MapLaps then
CompletedRace(Player)
else
CompletedLap(Player)
end
end
end
end
end
end
end)
end
If this doesn’t work, are you receiving any errors from the ouput?
Still isn’t working…
Also, no errors in the output…
I determined where I put the comment with print() that the stuff below doesn’t run at all…
Before running the rest of the code, I think you should make an if statement checking if the player exists, maybe that will fix the issue.
Updated code:
for _, KeyCheckpoint in pairs(Checkpoints:GetChildren()) do
KeyCheckpoint.Touched:Connect(function(CharacterPart)
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
local Player = Players:GetPlayerFromCharacter(CharacterPart.Parent)
if Player then -- makes sure player exists
if KeyCheckpoint.Name ~= "EndRace" then
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
SetCheckpoint(Player, KeyCheckpoint, true)
end
else
if not Player:GetAttribute("PlayerCompleted") then
local Valid: boolean = true
for AttributeName, AttributeValue in pairs(Player.KeyCheckpoints:GetAttributes()) do
if not AttributeValue then
Valid = false
end
end
if Valid then
if BloxyKartService.Gamemode ~= "FreeRoam" then
if Player:GetAttribute("LapNumber") == MapLaps then
CompletedRace(Player)
else
CompletedLap(Player)
end
end
end
end
end
end
end
end)
end
Have you tried printing the path of CharacterPart
?
for _, KeyCheckpoint in pairs(Checkpoints:GetChildren()) do
KeyCheckpoint.Touched:Connect(function(CharacterPart)
print("Touched by", CharacterPart:GetFullName())
I added prints like this:
if BloxyKartService.Gamemode ~= "Battle" then
for _, KeyCheckpoint in pairs(Checkpoints:GetChildren()) do
print("Looping")
KeyCheckpoint.Touched:Connect(function(CharacterPart)
print("Touched")
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
print("Humanoid :)")
local Player = Players:GetPlayerFromCharacter(CharacterPart.Parent)
if Player then -- makes sure player exists
print("Player")
if KeyCheckpoint.Name ~= "EndRace" then
if CharacterPart.Parent:FindFirstChildOfClass("Humanoid") then
SetCheckpoint(Player, KeyCheckpoint, true)
end
else
if not Player:GetAttribute("PlayerCompleted") then
local Valid: boolean = true
for AttributeName, AttributeValue in pairs(Player.KeyCheckpoints:GetAttributes()) do
if not AttributeValue then
Valid = false
end
end
if Valid then
if BloxyKartService.Gamemode ~= "FreeRoam" then
if Player:GetAttribute("LapNumber") == MapLaps then
CompletedRace(Player)
else
CompletedLap(Player)
end
end
end
end
end
end
end
end)
end
end
And here is the result:
Still isn’t working…
Hm… I don’t see my Player in there anywhere…
Alright, follow up…
I fixed the issue, and apparently, custom characters had CanTouch set to false…
I guess the change was that I didn’t have a custom character equipped when testing…
Fixed it with this command in the command bar:
for _, Characters in pairs(game.ReplicatedStorage.Characters:GetDescendants()) do if Characters:IsA("BasePart") then Characters.CanTouch = true end end
1 Like