should I call the PlayerPickedUpItem function at some point because after I pick up a gun it doesn’t respawn one after the given wait time.
Also, the models are still not spawning in on top of the spawn points, the handle is but not the gun. There’s really no difference then what I had before, unfortunately. I know you’ve been trying your best to help me, and I appreciate it all but for whatever reason this thing is being stubborn.
Try this script that I modified again. I’m sorry this should not be this hard for me to debug this script.
local items = game.ReplicatedStorage.Items
local seconds = math.random(1, 5)
local spawnedItems = {}
local function chooseSpawn()
local spawns = workspace.Teir_1_Loot_Spawn_Points:GetChildren()
return spawns[math.random(1, #spawns)]
end
local function chooseItem()
local item = items:GetChildren()[math.random(1, #items:GetChildren())]:Clone()
return item
end
local function respawnItem(spawn)
if spawnedItems[spawn] then
spawnedItems[spawn]:Destroy()
wait(10) -- Adjust the delay as needed
end
local newItem = chooseItem()
newItem.Parent = spawn
newItem.Handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0) -- Adjust the offset here aswel
spawnedItems[spawn] = newItem
end
while true do
local spawn = chooseSpawn()
if not spawnedItems[spawn] then
respawnItem(spawn)
end
wait(seconds)
end
Nope, lol still doesn’t respawn another gun after I pick one up. Are you sure you don’t want to come to my game a see what’s going on, lol it might make it easier for you?
I don’t think I would be better in studio. If this does not work then I do not believe I can help you anymore.
local items = game.ReplicatedStorage.Items
local seconds = math.random(1, 5)
local spawnedItems = {}
local function chooseSpawn()
local spawns = workspace.Teir_1_Loot_Spawn_Points:GetChildren()
return spawns[math.random(1, #spawns)]
end
local function chooseItem()
local item = items:GetChildren()[math.random(1, #items:GetChildren())]:Clone()
return item
end
local function respawnItem(spawn)
if spawnedItems[spawn] then
spawnedItems[spawn]:Destroy()
wait(10) -- Adjust the delay as needed
end
local newItem = chooseItem()
newItem.Parent = spawn
newItem.Handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0) -- Adjust the offset aswell
spawnedItems[spawn] = newItem
end
local function PlayerPickedUpItem(spawn)
if spawnedItems[spawn] then
spawnedItems[spawn]:Destroy()
spawnedItems[spawn] = nil
respawnItem(spawn)
end
end
while true do
local spawn = chooseSpawn()
if not spawnedItems[spawn] then
respawnItem(spawn)
end
wait(seconds)
end
It works! you did a great job debugging this for me, thank you again. The only problem was that the spawned item Handle was not Anchored, and the Prox Prompt was falling too low to be able to pick up the gun, it’s still not respawning after but that’s fine.
local items = game.ReplicatedStorage.Items -- Replace "Items" with the actual name of your folder containing the items.
local seconds = math.random(1, 5) -- Adjust the respawn time as needed
local spawnedItems = {} -- Table to keep track of spawned items
local function chooseSpawn() -- Function to choose a random spawn point
local spawns = workspace.Teir_1_Loot_Spawn_Points:GetChildren() -- Get all spawn points from the folder
return spawns[math.random(1, #spawns)] -- Return a random spawn point
end
local function chooseItem() -- Function to choose a random item from the folder
local item = items:GetChildren()[math.random(1, #items:GetChildren())]:Clone() -- Clone the item and return it
return item -- Return the cloned item
end
local function respawnItem(spawn) -- Function to respawn an item at a spawn point
-- Check if the spawn point already has an item spawned
if spawnedItems[spawn] then -- If it does, destroy the existing item
spawnedItems[spawn]:Destroy() -- Destroy the item
task.wait(10) -- Adjust the delay as needed
end
local newItem = chooseItem() -- Choose a random item from the folder
newItem.Parent = spawn --Parent the same item to the spawn
newItem.Handle.Anchored = true -- Anchor the item to prevent it from falling due to gravity
newItem.Handle.CanCollide = false -- Disable collisions to prevent it from colliding with other objects
newItem.Handle.CFrame = spawn.CFrame * CFrame.new(0,1,0) -- Adjust the offset aswell
spawnedItems[spawn] = newItem -- Update the spawnedItems table with the new item
print("Item spawned at spawn point:", spawn.Name) -- Print a message to confirm the spawn
end
local function PlayerPickedUpItem(spawn) -- Function to handle when a player picks up an item
-- Check if the player picked up the item by comparing the spawn point where the item was originally spawned
if spawnedItems[spawn] then -- If it matches, remove the item from the spawnedItems table and respawn it after a delay
spawnedItems[spawn]:Destroy() -- Destroy the item
spawnedItems[spawn] = nil -- Remove the reference to the item from the spawnedItems table
wait(10) -- Adjust the delay as needed
respawnItem(spawn) -- Respawn the item
end
end
while true do --
local spawn = chooseSpawn() -- Choose a random spawn point
if not spawnedItems[spawn] then -- If the spawn point is not currently occupied, spawn an item at it
respawnItem(spawn) -- Respawn the item at the spawn point
end
task.wait(seconds)
end
Oh, I understand now. Thank you for this because this was a learning experience for the both of us. I was happy to debug your script, even if something still isn’t working correctly.