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.
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
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
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
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
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.
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.
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?
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
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