Hi, devs! I’m trying to make a jail system. The problem, when I press the “jail” button… Well, errors happen. I’m not sure if I should go into a full nuclear printing or ask you guys if I made a fatal mistake. You press the button and the target player should be teleported into a box, and if his magnitude from the part he’s teleported to is higher than 15 then it teleports the user back. I believe the jail datastore is broken as well? I tried a few methods of doing this before and none of them worked.
QNA
Q: Is this in a localscript?
A: No, it’s a server script.
Q:PlayerToWarn is nil?
A: No, it is not.
Q:Any errors in output?
A: 08:29:26.725 ServerScriptService.ModGUI.Main:214: attempt to index nil with 'Connect' - Server - Main:214 — Erroring at jail.OnServerEvent:Connect
Code:
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.Position = game.Workspace:FindFirstChild("Torment").Position
table.insert(jail, playerToJail)
if table.find(jail, playerToJail) then
local mag = (game.Workspace:FindFirstChild("Torment").Position - game.Workspace:FindFirstChild(playerToJail).HumanoidRootPart.Position).Magnitude
while true do
wait(60)
if mag > 15 then
game.Workspace:FindFirstChild(playerToJail).HumanoidRootPart.Position = game.Workspace:FindFirstChild("Torment").Position
end
end
end
end
end
end)
Data:
local DataStore = game:GetService("DataStoreService")
local jailData = DataStore:GetDataStore("Jailed")
game.Players.PlayerAdded:Connect(function(player)
local playerID = player.UserId
local jailed
local success, errormessage = pcall(function()
jailed = jailData:GetAsync(playerID)
end)
if jailed then
game.Workspace:FindFirstChild(player).HumanoidRootPart.Position = game.Workspace:FindFirstChild("Torment").Position
local mag = (game.Workspace:FindFirstChild("Torment").Position - game.Workspace:FindFirstChild(player).HumanoidRootPart.Position).Magnitude
while true do
wait(60)
if mag > 15 then
game.Workspace:FindFirstChild(player).HumanoidRootPart.Position = game.Workspace:FindFirstChild("Torment").Position
end
end
end
end
end)
I’m unsure of what to do.