[SOLVED] How to Make a Randomized Item Spawner

Could you elaborate on that issue?

1 Like

@LVSKCNBL
ezgif-2-fa0846d70a

As you can see the Item is futile because it isn’t interactable.

Does the code provide any errors in the output?

1 Like

New Script:

-- EToPickUp Script
local ToolNames = {"Battery"} -- Change Item to your item name and move it to ServerStorage
local Storage = game.ServerStorage.RareItems


local Part = script.Parent
local ProximityPrompt = Part:WaitForChild("ProximityPrompt")


ProximityPrompt.Triggered:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
				if Backpack:FindFirstChild(Tool.Name) == nil then
					game:GetService("ServerStorage").BatteryPickup:Fire()
					Tool:clone().Parent = Backpack
					Tool:Destroy()
				end	
			end
		end
	end
end)

Original Script:

-- EToPickUp Script
local ToolNames = {"GroupCola"} -- Change Item to your item name and move it to ServerStorage
local Storage = game.ServerStorage.RareItems


local Part = script.Parent
local ProximityPrompt = Part:WaitForChild("ProximityPrompt")

ProximityPrompt.Triggered:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
				if Backpack:FindFirstChild(Tool.Name) == nil then
					Tool:clone().Parent = Backpack
				end	
			end
		end
	end
end)

You’re destroying the tool in ServerStorage right after putting it in the backpack.

Instead of Tool:Destroy() do Part:Destroy().

1 Like

there is still no difference between the both.

Make sure the script is actually finding the item then. From what you wrote it’ll check if Tool isn’t nil, so make sure it isn’t.

After the if statement, add a print statement, like so:

if Tool then
   print("Tool found.")
else 
   print("Tool is nil.")
end
1 Like
local ToolNames = {"Battery"} -- Change Item to your item name and move it to ServerStorage
local Storage = game.ServerStorage.RareItems


local Part = script.Parent
local ProximityPrompt = Part:WaitForChild("ProximityPrompt")

ProximityPrompt.Triggered:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
				if Backpack:FindFirstChild(Tool.Name) == nil then
					Tool:clone().Parent = Backpack
					Part:Destroy()
				end	
			end
		end
	end
end)

Can I use this Script because it actually gives me the item.

3 Likes

Yes, that would be the script to use then.

1 Like

I tried taking the Battery and it didn’t move to a different position.

As I mentioned before would it be easier if I would to just send it all in a kit?

I feel like that might be an issue with how you run it’s position. But if the .CFrame and the Vector you’re adding are on a separate lines, put them on the same line, so it looks like this:

clone.CFrame = toolSpawns[math.random(1,#toolSpawns)].CFrame + Vector3.new(2,1,0) -- Picks one random Spawns CFrame with Y offset of 1 stud.

Try this I highly recommended this will save a heck tone of time.
BatterySystem.rbxm (46.5 KB)

@LVSKCNBL FINALY GOT IT WORKING!!

My silly a$$ didn’t put the Battery Tool in ServerStorage and I had to add this – game:GetService("ServerStorage").BatteryPickUp.BatteryRespawn:Fire()

That was the conclusion I was coming to as I worked on it.

1 Like

lol sorry about that, it is currently 5am and I’ve been working non-stop for the last 2 weeks.

My next piece of advice now is to get some sleep.

1 Like

than you very much for helping me.:relieved:

1 Like