Jail script, teleports target player upon pressing button and then checks the magnitude of the player to see if he glitched or exploited out. Does not work, does not error.
Script:
jail.OnServerEvent:Connect(function(player, playerToJail)
if not table.find(ADMIN, player.UserId) then return end
if not game.Players:FindFirstChild(playerToJail) then print("Player not in-game!") return end
playeruserID = getUserIdFromUsername(playerToJail)
if playeruserID == 1 then
return
else
local success, errormessage = pcall(function()
JailData:SetAsync(playeruserID)
end)
if success then
game.Workspace:FindFirstChild(playerToJail).HumanoidRootPart.CFrame = game.Workspace:FindFirstChild("Torment").CFrame
local mag = (game.Workspace:FindFirstChild("Torment").CFrame - game.Workspace:FindFirstChild(playerToJail).HumanoidRootPart.CFrame).Magnitude
while true do
wait(60)
if mag > 15 then
game.Workspace:FindFirstChild(playerToJail).HumanoidRootPart.CFrame = game.Workspace:FindFirstChild("Torment").CFrame
end
end
end
end
end)
Jail data errors saying that i tried to call a nil value of âHumanoidRootPartâ, i tried putting WaitForChild and FindFirstChild but it said the same thing "tried to call nil value of âWaitForChildâ or âFindFirstChildâ.
Jail Data:
local DataStore = game:GetService("DataStoreService")
local jailData = DataStore:GetDataStore("Jailed")
local man = {}
game.Players.PlayerAdded:Connect(function(player)
wait(10)
local char = player.Character
local HumanoidRootPart = char.HumanoidRootPart
local playerID = player.UserId
local jailed
local success, errormessage = pcall(function()
jailed = jailData:GetAsync(playerID)
end)
if jailed then
game.Workspace:FindFirstChild(player):WaitForChild("HumanoidRootPart").CFrame = game.Workspace:FindFirstChild("Torment").CFrame
local mag = (game.Workspace:FindFirstChild("Torment").CFrame - game.Workspace:FindFirstChild(player).HumanoidRootPart.CFrame).Magnitude
while true do
wait(60)
if mag > 15 then
game.Workspace:FindFirstChild(player).HumanoidRootPart.CFrame = game.Workspace:FindFirstChild("Torment").CFrame
end
end
end
end)
You should implement another sanity check if success returned back as true, otherwise itâll bring that error & make sure to print what jailed really gives you
Also you should encase this with/inside a CharacterAdded event as well so itâll detect whenever every time the Character respawns:
game.Players.PlayerAdded:Connect(function(player)
wait(10)
local char = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = char.HumanoidRootPart
local playerID = player.UserId
local jailed
local success, errormessage = pcall(function()
jailed = jailData:GetAsync(playerID)
end)
print(jailed)
if jailed and success then
game.Workspace:FindFirstChild(player):WaitForChild("HumanoidRootPart").CFrame = game.Workspace:FindFirstChild("Torment").CFrame
local mag = (game.Workspace:FindFirstChild("Torment").CFrame - game.Workspace:FindFirstChild(player).HumanoidRootPart.CFrame).Magnitude
while true do
wait(60)
if mag > 15 then
game.Workspace:FindFirstChild(player).HumanoidRootPart.CFrame = game.Workspace:FindFirstChild("Torment").CFrame
end
end
else
warn(errormessage)
end
end)
Judging by the error, playerToJail could be referenced as a nil value if you havenât defined it property which is why youâre getting the HumanoidRootPart nil values even if you call WaitForChild/FindFirstChild on it
Iâd recommend adding print statements to see what itâs really defined at
game.Players.PlayerAdded:Connect(function(player)
local playerID = player.UserId
local jailed
local success, errormessage = pcall(function()
jailed = jailData:GetAsync(playerID)
end)
if jailed and success then
table.insert(jail, player)
if table.find(jail, player) then
game.Workspace:FindFirstChild(player.Name):WaitForChild("HumanoidRootPart").Position = game.Workspace:FindFirstChild("Torment").Position
local mag = (game.Workspace:FindFirstChild("Torment").Position - game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.Position).Magnitude
while true do
wait(60)
if mag > 15 then
game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.Position = game.Workspace:FindFirstChild("Torment").Position
end
end
end
end
end)