My gun Model spawns in a different spot in workspace then Tool

I’m making a tool spawner, but the model I have as a child of the tool spawns in different location in workspace. I’ve notice that wherever the model is in the workspace, is the position it’s in when the tool spawns. The Proximity Prompt shows on the part in workspace when the tool is spawns in, but the model is not in same spot.

WORKSPACE:


EXPLORER:
spawn2

SCRIPT:

local items = game.ReplicatedStorage.Items
local secconds = math.random(1,5)

local function chooseSpawn()
	local _spawn = spawns:GetChildren()[math.random(1,#spawns:GetChildren())]
	
	return _spawn

end

local function chooseItem()
	local item = items:GetChildren()[math.random(1,#items:GetChildren())]
	
	return item
	
end

while wait(secconds) do
	local _spawm = chooseSpawn()
	local Item = chooseItem()
	local clone = Item:Clone()
	
	
	clone.Parent = workspace.Teir_1_Loot_Spawn_Points.Part
	clone.Handle.CFrame = _spawm.CFrame * CFrame.new(0,1,0)
end
1 Like

Did you weld all the parts in the tool to the handle?

1 Like

not really sure how to do that…

1 Like

you need to adjust the CFrame of the item after cloning it.

In your script you are setting the CFrame of the clone’s Handle but it seems like there might be a typo in the variable names. Im saying this because of

.

1 Like

Ok would you have have any suggestions on what I should do?

1 Like

Okay here you go. I did this after I saw your post

local items = game.ReplicatedStorage.Items
local seconds = math.random(1, 5)

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())]
    return item:Clone()
end

while wait(seconds) do
    local spawn = chooseSpawn()
    local item = chooseItem()
    
    item.Parent = workspace.Teir_1_Loot_Spawn_Points.Part
    item.Handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0)
end

Inform me if this does not work.

2 Likes

Hello, from this video you showed me I believe the error is that it spawns too many guns correct? If so then do you just want 1 gun to spawn?

yeah, I also noticed that the formation of the gun pile is the same as the spawn parts, but not over top of them lol.

is there a way to only allow the spawn to produce one gun, unless its pickup by the player then it would spawn another?

Alrighty, I’ll fix these errors.

1 Like

I have addressed these errors that I made, here is what I did:

local items = game.ReplicatedStorage.Items
local seconds = math.random(1, 5)

local function chooseSpawn()
    local spawns = workspace.Teir_1_Loot_Spawn_Points:GetChildren()
    return spawns[math.random(1, #spawns)]
end

local spawnedItems = {}

local function chooseItem()
    local item = items:GetChildren()[math.random(1, #items:GetChildren())]
    return item:Clone()
end

while wait(seconds) do
    local spawn = chooseSpawn()
    
    if not spawnedItems[spawn] then
        local item = chooseItem()
        item.Parent = spawn
        item.Handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0)
        
        spawnedItems[spawn] = item
    end
end


local function PlayerPickedUpItem(spawn)
    if spawnedItems[spawn] then
        spawnedItems[spawn]:Destroy()
        spawnedItems[spawn] = nil
        
        
        wait(10)  -- Adjust the delay as needed
        local newItem = chooseItem()
        newItem.Parent = spawn
        newItem.Handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0)
        
        spawnedItems[spawn] = newItem
    end
end
1 Like

it works perfect just the models and handle don’t line up together now at the spawn part, but I’ll mess around with and see if I can’t iron out the wrinkles, I don’t want to hold you up all day, it’s just being stupid.

I don’t mind helping you. Here use this:

local items = game.ReplicatedStorage.Items
local seconds = math.random(1, 5)

local function chooseSpawn()
    local spawns = workspace.Teir_1_Loot_Spawn_Points:GetChildren()
    return spawns[math.random(1, #spawns)]
end

local spawnedItems = {}

local function chooseItem()
    local item = items:GetChildren()[math.random(1, #items:GetChildren())]
    return item:Clone()
end

while wait(seconds) do
    local spawn = chooseSpawn()
    
    if not spawnedItems[spawn] then
        local item = chooseItem()
        item.Parent = spawn
        item.Handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0)  -- Adjust the offset here to align the handle with the spawn location
        
        spawnedItems[spawn] = item
    end
end


local function PlayerPickedUpItem(spawn)
    if spawnedItems[spawn] then
        spawnedItems[spawn]:Destroy()
        spawnedItems[spawn] = nil
        
        
        wait(10)  -- Adjust the delay as needed
        local newItem = chooseItem()
        newItem.Parent = spawn
        newItem.Handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0)  -- Adjust the offset here as well
        
        spawnedItems[spawn] = newItem
    end
end

This was a small edit to the script. I also enjoy doing this lol.

1 Like

I really can’t figure out why it’s doing this would it help you out at all to see it first hand I can add you to team create, maybe mite still to you with everything in front of you?

Im confused now also, I do not know what to do. Im very sorry

Why don’t you PivotTo the clone to the spawn? You’re only setting the Handle’s CFrame so the ProximityPrompt part isn’t necessarily near the gun when it’s moved. PivotTo will move all the parts.

local items = game.ReplicatedStorage.Items
local secconds = math.random(1, 5)

local function chooseSpawn()
    local spawns = workspace.Teir_1_Loot_Spawn_Points:GetChildren()
    local spawn = spawns[math.random(1, #spawns)]
    return spawn
end

local function chooseItem()
    local item = items:GetChildren()[math.random(1, #items:GetChildren())]
    return item
end

while wait(secconds) do
    local spawn = chooseSpawn()
    local item = chooseItem()
    local clone = item:Clone()
    
    clone.Parent = workspace.Teir_1_Loot_Spawn_Points
    
    local tool = Instance.new("Tool")
    tool.Name = "ToolName"
    tool.Parent = game.Players.LocalPlayer.Backpack
    
    local handle = clone:FindFirstChild("Handle")
    if handle then
        handle.CFrame = spawn.CFrame * CFrame.new(0, 1, 0)
        handle.Parent = tool
    end
end

Oh so its spinning I will try to modify this script to fix this error.

Here, I added a rotation adjustment to the CFrame of the guns’ Handle. The CFrame.Angles(0, 0, 0) sets the rotation to 0 degrees in all axes, which preventing any spinning motion. Anyways, Here is the modified script

local items = game.ReplicatedStorage.Items
local seconds = math.random(1, 5)

local function chooseSpawn()
    local spawns = workspace.Teir_1_Loot_Spawn_Points:GetChildren()
    return spawns[math.random(1, #spawns)]
end

local spawnedItems = {}

local function chooseItem()
    local item = items:GetChildren()[math.random(1, #items:GetChildren())]
    return item:Clone()
end

while wait(seconds) do
    local spawn = chooseSpawn()
    
    if not spawnedItems[spawn] then
        local item = chooseItem()
        item.Parent = spawn
        item.Handle.CFrame = spawn.CFrame * CFrame.Angles(0, 0, 0) + Vector3.new(0, 1, 0)  -- Adjust the offset and rotation here 
        
        spawnedItems[spawn] = item
    end
end


local function PlayerPickedUpItem(spawn)
    if spawnedItems[spawn] then
        spawnedItems[spawn]:Destroy()
        spawnedItems[spawn] = nil
        
        
        wait(10)  -- Adjust the delay as needed
        local newItem = chooseItem()
        newItem.Parent = spawn
        newItem.Handle.CFrame = spawn.CFrame * CFrame.Angles(0, 0, 0) + Vector3.new(0, 1, 0)  -- Adjust the offset and rotation here as well
        
        spawnedItems[spawn] = newItem
    end
end