Issue with tool garbaging script

I’m trying to make a garbage model that whenever I click it’s flap or latch It moves up and all the tools in my backpack and all the tools I have equipped are deleted/destroyed. The problem is I have instanced tools which are in the backpack but in my scripts don’t act as children and therefore cannot be used.I’ve tried using module scripts to make a base for the tools I wanted to destroy and create, I also tried using collection service(which made me very confused), and I moved around my script a lot.

This script is supposed to delete all the things in the backpack and whatever is equipped. I didn’t put what was equipped yet because my issues were to severe to left unhandled.

local touch = workspace.Trash.Layer
touch.ClickDetector.MouseClick:Connect(function(plr)
	local tool = plr.Backpack:GetChildren()
	game.ReplicatedStorage.Events.TrashEvent:FireClient(plr, touch)
	for i,v in pairs(tool) do
		v:Destroy()
	end
end)

This is the local script in the startergui that the server script fires to which makes the latch open for one player and close.

game.ReplicatedStorage.Events.TrashEvent.OnClientEvent:Connect(function(touch)
	for i = 1,30 do
		task.wait()
		local flap = touch:GetPivot()
		touch:PivotTo(flap * CFrame.Angles(0,0,math.rad(3)))
	end
	task.wait(4)
	for i = 1,30 do
		task.wait()
		local flap = touch:GetPivot()
		touch:PivotTo(flap * CFrame.Angles(0,0,math.rad(-3)))
	end
end)

This script is a tool I’m creating/instancing:

game.ReplicatedStorage.Events.MakeFoodEvent.OnClientEvent:Connect(function()
	local placingfolder = workspace:WaitForChild("PlacingPartsFolder"):WaitForChild("Folder")
	print(placingfolder)
	local plr = game.Players.LocalPlayer
	local part1 = workspace:WaitForChild("PlateInteraction1")
	local plate = workspace:WaitForChild("Handle")
	local num = -3
	local parts = placingfolder:GetChildren()
	local tool = Instance.new("Tool", plr.Backpack)
	local children = tool:GetChildren()
	local clonedplate = plate:Clone()
	part1.ProximityPrompt.Enabled = true
	clonedplate.Anchored = false
	workspace.PlateInteraction1.Position = Vector3.new(32.375, 5.625, 23.25)
	tool.GripPos = tool.GripPos + Vector3.new(0,1,0)
	tool.GripUp = tool.GripUp + Vector3.new(-100,0,0)
	tool.Name = "Food"
	tool.PrimaryPart = clonedplate
	clonedplate.Parent = tool
	clonedplate.CanCollide = false
	for i,v in pairs(parts) do
		local weld = Instance.new("WeldConstraint", clonedplate)
		weld.Part0 = clonedplate
		weld.Part1 = v
		v.Parent = tool
		v.Anchored = false
		v.CanCollide = false
		v.Position = v.Position + Vector3.new(0,-0.25,0)
	end
	placingfolder:Destroy()
end)

If necessary this is the script firing the previous script:

local part = workspace.ExecutePlate
local plate = workspace.Handle
part.ClickDetector.MouseClick:Connect(function(plr)
	game.ReplicatedStorage.Events.MakeFoodEvent:FireClient(plr)
end)

Nevermind, I fixed this script by syncing the local script and server script using remote functions.

Mark your own reply stating it was fixed as the solution please, Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.