200 Robux to Modify Script

the script works great and im still down to pay. I want to figure out how to change this script a little though. Ill pay200 robux now if you are able to script me a function where instead of spawning the random model into workspace it spawns into 6 of the random drawers in workspace.
this is the script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Http = game:GetService("HttpService")

local remoteEvent = ReplicatedStorage:WaitForChild("ToolClaimEvent")
local lootsFolder = ServerStorage:WaitForChild("Loots")


local function handleLootItems(lootModel: Model)
	local claimedOnes = {}
	for _,part in lootModel:GetChildren() do
		if not part:IsA("BasePart") then continue end
		
		local toolGUID = Http:GenerateGUID()
		
		local detect = Instance.new("ClickDetector")
		detect.Parent = part
		detect.MaxActivationDistance = 32
		
		detect.MouseClick:Connect(function(player: Player)
			local tool = game:GetService("ServerStorage"):WaitForChild("Items"):FindFirstChild(part.Name) -- Checks if theres a tool with the same name as the clicking part
			if not tool then return end
			local playerBackpack = player:WaitForChild("Backpack")

			if not claimedOnes[player.UserId] then claimedOnes[player.UserId] = {} end
			if not claimedOnes[player.UserId][toolGUID] then
				tool:Clone().Parent = playerBackpack
				remoteEvent:FireClient(player,part)
				claimedOnes[player.UserId][toolGUID] = true
			end
		end)
	end
end

local function spawnLoots(lootName: string,spawnCFrame)
	local existing = lootsFolder:FindFirstChild(lootName)
	if not existing then return end
	local cloned = existing:Clone()

	pcall(function()
		if cloned.PrimaryPart and spawnCFrame then
			cloned.PrimaryPart.CFrame = spawnCFrame
		end
	end)

	cloned.Parent = workspace:WaitForChild("Loots")
	handleLootItems(cloned)
end

local allLoots = {"LootTools1","LootTools2","LootTools3","LootTools4"}
spawnLoots(allLoots[math.random(1,#allLoots)]) -- remove?
while task.wait(15) do
	if math.random()>0.75 then
		if #lootsFolder:GetChildren()==0 then
			spawnLoots(allLoots[math.random(1,#allLoots)])
		end
	end
end

Screenshot 2023-11-10 at 9.06.28 AM
Screenshot 2023-11-10 at 9.06.41 AM
so what i want basically is for every part in the model that spawns in workspace to teleport to a random drawer there are 6 models and 9 drawers in each.

1 Like

Could you include the model? I want to find out the offset needed for the object to spawn in the right place inside the drawer.

2 Likes

do u want another test place i can hook u up with that. ill put everything in there.

2 Likes

Sure.

1 Like

Random Loot Spawn Test.rbxl (162.2 KB)

sorry it took so long i had to set it all up.

1 Like

Done, I just made it loop over every tool inside a random loot box and put that tool into a random drawer.

File:
Random Loot Spawn Test.rbxl (161.6 KB)

1 Like

let me test it really quickly.

alright so it somewhat works but all the tools are not clickable in the drawers now and it seems like they all spawn in 1 drawer. is there a way to make it so they spawn in a random drawers? not just 1?

also the tools go in the drawer sideways. just make it so they stay upright and ill work on the sizing after this is done.

Done:
Random Loot Spawn Test.rbxl (161.7 KB)

1 Like

ima run a few tests then pay u!

quick question, the way to make the tools move up more on the drawer is this line correct?

		cloned:PivotTo(randomDrawer:GetPivot() * CFrame.Angles(0, 0, math.rad(-90)))

or is there a line i have to add to move the position up a little?

		cloned:PivotTo(randomDrawer:GetPivot() * CFrame.Angles(0, 0, math.rad(-90)) * CFrame.new(0, 0.5, 0))

Change it to this:

cloned:PivotTo(randomDrawer:GetPivot() * CFrame.Angles(0, 0, math.rad(-90)) * CFrame.new(0, yourYOffsetHere, 0))

Put the y offset as the yourYOffsetHere

thats all i had to do to move it up.

make a gamepass or something and send it to me ill pay u when u ready.

Don’t pay me.

2 Likes

please let me bro, u helped me so much over the past few weeks!

its honestly the least i could do for u.