Alright so I have an obby and I recently added this detection system which checks if the new stage a player touches is +1 above their previous stage. If it’s not, it should kick the player for stage jumping. But it doesn’t seem to work, any ideas?
humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name) and tonumber(touch.Name) == tonumber(stage.Value)) + 1 then
stage.Value = touch.Name
elseif (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) + 1 then
plr:Kick("LDCO detected stage jump")
print(plr.Name.." stage jumped from Stage "..stage.Value.." to "..touch.Name.." and was kicked")
end
end
end)
It looks like the script is a LocalScript. By any chance, is it?
In hindsight, it isn’t that useful by using Humanoid.Touched, you’d rather use BasePart.Touched instead because this will avoid odd triggers from the Humanoid touching things that isn’t one of the checkpoints.
He already checks if touched part is a checkpoint by checking is it is parented by checkpoints folder with this line though: if touch.Parent == checkpoints then
At least it seems like it.
This is an easier way to write the code and just make sure your checkpoints variable is pointing to the folder where the checkpoints are
the below code has prints in it to help you debug it also
Humanoid.Touched:Connect(function(touch)
print('Touched ', touch)
if touch:IsDescendantOf(checkpoints) then -- make sure checkpoints is the folder of checkpoints not the table/object
local TouchNumber = tonumber(touch.Name)
if not TouchNumber then return end -- not a number just return
print('Touched is a number')
if TouchNumber == (tonumber(stage.Value) + 1) then
print('Stage is ok')
stage.Value = touch.Name
elseif TouchNumber > (tonumber(stage.Value) + 1) then
plr:Kick("LDCO detected stage jump")
print(plr.Name .. " stage jumped from Stage ".. stage.Value .." to ".. touch.Name .." and was kicked")
end
end
end)