Hello, I’m trying to check what tools are in the players backpack. If there is any tools in their backpack, it makes the enable variable false. It’s not working, but it is printing the function I called. No errors in the output.
Script:
local blur = game.Lighting.BlurShop
local button = script.Parent.First.Play
local plr = game.Players.LocalPlayer
for i, v in pairs(plr.Backpack:GetChildren()) do
if v:IsA("Tool") then
print(v)
script.Parent.Enabled = false
end
end
blur.Enabled = true
plr.CameraMode = Enum.CameraMode.Classic
plr.CameraMaxZoomDistance = 50
plr.CameraMinZoomDistance = 50
script.Parent.Enabled = true
local health = Instance.new("IntValue", script.Parent)
health.Name = "Health"
health.Value = plr.Character:WaitForChild("Humanoid").MaxHealth
plr.Character:WaitForChild("Humanoid").MaxHealth = math.huge
plr.Character:WaitForChild("Humanoid").Health = math.huge
--plr.PlayerGui.Ammo.Enabled = false
plr.PlayerGui.Health.Enabled = false
if plr.PlayerGui:WaitForChild("HotBarGUI") then
plr.PlayerGui.HotBarGUI.Enabled = false
end
plr.PlayerGui.PlayerInfo.Enabled = false
plr.PlayerGui:WaitForChild("Stamina").Enabled = false
button.MouseButton1Click:Connect(function()
script.Parent.SelectWeapon.Visible = true
for i, v in pairs(script.Parent.First:GetChildren()) do
if v:IsA("ImageButton") or v:IsA("TextButton") or v:IsA("TextLabel") then
v.Visible = false
end
end
end)
I’m pretty sure you’re actually disabling the Script’s parent?
for i, v in pairs(plr.Backpack:GetChildren()) do
if v:IsA("Tool") then
print(v)
script.Parent.Enabled = false -- Did you mean v.Enabled = false?
end
end
Do you want the ScreenGui to be disabled when a tool is inside a player’s backpack?
If so, should it work when a tool is already inside the player’s Backpack when loading, or should it disappear when a player grabs a tool?
my bad didn’t read your last reply.
You made a for loop, without wrapping it in a function statement, and then connecting it to the ChildAdded event (and perhaps event ChildRemoved if you want the UI to reappear) when a player grabs a tool.
local function disableIfToolsPresent()
for i, v in pairs(plr.Backpack:GetChildren()) do
if v:IsA("Tool") then
print(v)
script.Parent.Enabled = false
return -- stops when a tool is found
end
end
-- (only if you need the ui to reappear, otherwise remove this.) if a tool is not found, then...
script.Parent.Enabled = true
end
disableIfToolsPresent() - if a tool is already in the backpack, just in case.
--... other code stuff you have, up until the button part ...
plr.Backpack.ChildAdded:Connect(disableIfToolsPresent)
-- if you want the UI to reappear when you have no tools...
plr.Backpack.ChildRemoved:Connect(disableIfToolsPresent)
The loop is in a function statement. Now you can connect it to events.