I do not know how to explain it, but it will go through all these checks, then it just breaks. (Works the first time, breaks the second)
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local player = game:GetService("Players")
local player = player.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local isHolding = player.isHolding
workspace.Converter.Convert.Enabled = false
isHolding.Changed:Connect(function()
if isHolding.Value == true then
local Trash = workspace.TrashFolder:GetDescendants() -- Refreshes Descendants
for _, descendant in ipairs(Trash) do
if descendant:IsA("Folder") and descendant.Name == 'Scripts' then
if descendant.Interact then -- Breaks here (Line: 15)
descendant.Interact.Grab.ActionText = 'Replace'
end
end
end
workspace.Converter.Convert.Enabled = true
else
local Trash = workspace.TrashFolder:GetDescendants()
for _, descendant in ipairs(Trash) do
if descendant:IsA("Folder") and descendant.Name == 'Scripts' then
if descendant.Interact.Grab then
descendant.Interact.Grab.ActionText = 'Grab'
end
end
end
workspace.Converter.Convert.Enabled = false
end
end)
Error:
09:50:30.398 Interact is not a valid member of Folder "Workspace.TrashFolder.Trash.Scripts" - Client - InteractBtnHandlers:15
Direct indexing will result in an error if the index is not found (in this case, the child).
To avoid this issue, use the FindFirstChild instance method in your statement.
Here’s a video showing of what’s happening.
Keep in mind this was working yesterday.
Updated Code (LocalScript):
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local isHolding = player.isHolding
workspace.Converter.Convert.Enabled = false
isHolding.Changed:Connect(function()
if isHolding.Value == true then
local Trash = workspace.TrashFolder:GetDescendants()
for _, descendant in ipairs(Trash) do
if descendant:IsA("Folder") and descendant.Name == 'Scripts' then
local interact = descendant:FindFirstChild("Interact") -- Found This
local grab = interact:FindFirstChild("Grab") -- Tried to do the same thing, did not find (it exists when I manually go through the explorer)
grab.ActionText = 'Replace'
end
end
workspace.Converter.Convert.Enabled = true
else
local Trash = workspace.TrashFolder:GetDescendants()
for _, descendant in ipairs(Trash) do
if descendant:IsA("Folder") and descendant.Name == 'Scripts' then
local interact = descendant:FindFirstChild("Interact")
local grab = interact:FindFirstChild("Grab")
grab.ActionText = 'Grab'
end
end
workspace.Converter.Convert.Enabled = false
end
end)
Code for the Blue Part (ServerScript):
local interact = script.Parent
local items = {
["Box"] = 1,
["Bag"] = 2,
["Can"] = 3,
["Furniture"] = 4,
}
interact.Triggered:Connect(function(player)
if player.Character or player.CharacterAdded:Wait() then
if player.Character.Tool.Handle and player:WaitForChild("isHolding").Value == true then
local trash = player.Character.Tool.Handle:GetDescendants()
for _, descendant in pairs(trash) do
for item, value in pairs(items) do
if descendant:IsA("StringValue") and descendant.Value == item then
descendant.Parent:Destroy()
for _, playingTracks in pairs(player.Character.Humanoid.Animator:GetPlayingAnimationTracks()) do
playingTracks:Stop()
end
player.leaderstats.Trash.Value += value
player.isHolding.Value = false -- Changing the isHolding State
end
end
end
end
end
end)