I'm making a shackle tool and I need to access the prisoner's playerGui when I click on him with the shackles. I'll mark the place where I'm having troubles. Could you help me figure out what's wrong?
local shackles = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local canJail = false
local studsToArrest = 20
function onEquipped()
print("Shackles equipped")
canJail = true
end
function onUnequipped()
print("Shackles unequipped")
canJail = false
end
function onActivation()
if mouse.Target.Parent:FindFirstChild("Humanoid") then
local prisoner = mouse.Target.Parent
local mag = (prisoner.Torso.Position - plr.Character.Torso.Position).magnitude
if mag <= studsToArrest then
if prisoner:FindFirstChild("timesJailed") then
prisoner.timesJailed.Value = prisoner.timesJailed.Value + 1
else
local tj = Instance.new("NumberValue", prisoner)
tj.Name = "timesJailed"
tj.Value = 1
end
if game.Workspace.Jail.jailSpawn1.Occupied.Value == false then
prisoner.Torso.CFrame = game.Workspace.Jail.jailSpawn1.CFrame + Vector3.new(0,2,0)
game.Workspace.Jail.jailSpawn1.Occupied.Value = true
elseif game.Workspace.Jail.jailSpawn2.Occupied.Value == false then
prisoner.Torso.CFrame = game.Workspace.Jail.jailSpawn2.CFrame + Vector3.new(0,2,0)
game.Workspace.Jail.jailSpawn2.Occupied.Value = true
elseif game.Workspace.Jail.jailSpawn3.Occupied.Value == false then
prisoner.Torso.CFrame = game.Workspace.Jail.jailSpawn3.CFrame + Vector3.new(0,2,0)
game.Workspace.Jail.jailSpawn3.Occupied.Value = true
elseif game.Workspace.Jail.jailSpawn4.Occupied.Value == false then
prisoner.Torso.CFrame = game.Workspace.Jail.jailSpawn4.CFrame + Vector3.new(0,2,0)
game.Workspace.Jail.jailSpawn4.Occupied.Value = true
elseif game.Workspace.Jail.jailSpawn5.Occupied.Value == false then
prisoner.Torso.CFrame = game.Workspace.Jail.jailSpawn5.CFrame + Vector3.new(0,2,0)
game.Workspace.Jail.jailSpawn5.Occupied.Value = true
elseif game.Workspace.Jail.jailSpawn6.Occupied.Value == false then
prisoner.Torso.CFrame = game.Workspace.Jail.jailSpawn6.CFrame + Vector3.new(0,2,0)
game.Workspace.Jail.jailSpawn6.Occupied.Value = true
else
print("All prison cells are full")
if plr.PlayerGui:FindFirstChild("Notifier") then
if plr.PlayerGui.Notifier == false then
plr.PlayerGui.Notifier.Enabled = true
for i = 1,0,-0.1 do
plr.PlayerGui.Notifier.notifier.TextTransparency = i
wait()
end
wait(2)
for i = 0,1,0.1 do
plr.PlayerGui.Notifier.notifier.TextTransparency = i
wait()
end
end
end
end
print(prisoner.Name.." has been jailed "..prisoner.timesJailed.Value.." times now...")
game.Players:GetPlayerFromCharacter(prisoner).TeamColor = BrickColor.new("Really black")
if prisoner.timesJailed.Value == 1 then
local prisonerPlr = game.Players:GetPlayerFromCharacter(prisoner)
for i,v in pairs(prisonerPlr:GetChildren()) do
print(v.Name) --I print out the children here
wait()
end
prisoner.PlayerGui.JailTimer.Frame.Visible = true --The error says playerGui doesnt exist in the player.
for i = 120,0,-1 do
print(i)
prisonerPlr.PlayerGui.JailTimer.Frame.Timer.Text = i
wait(1)
end
end
end
end
end
shackles.Equipped:connect(onEquipped)
shackles.Unequipped:connect(onUnequipped)
shackles.Activated:connect(onActivation)
