Spawning in objects doesn't work properly

So I’m having an issue with my capsule generator which doesn’t generate the models properly. I think it’s an issue with my code being a little old, however I am not sure how to solve this issue.

local generator = script.Parent
local storage = game:GetService('ServerStorage')
local objecttoclone = storage:WaitForChild('Capsule')

local function onUse()
	local clone = objecttoclone:Clone()
	clone.Parent = workspace
	clone.Position = generator.Position
end

local function cChange()
	local topband = objecttoclone.TopCap.Band
	local bottomband = objecttoclone.BottomCap.Band
	local base = objecttoclone.BottomCap.Base
	local setto = BrickColor.random()
	topband.BrickColor = setto
	bottomband.BrickColor = setto
	base.BrickColor = setto
end

while true do
	wait(10)
	cChange()
	onUse()
end

As shown in the video, one will spawn with the colour.
Also it does not spawn where the “spawner” is.
It immediately throws this error after:

  Position is not a valid member of Model "Workspace.Capsule"  -  Server - Script:8
  Stack Begin  -  Studio
  Script 'Workspace.Generator.Script', Line 8 - function onUse  -  Studio - Script:8
  Script 'Workspace.Generator.Script', Line 23  -  Studio - Script:23
  Stack End  -  Studio
1 Like
local generator = script.Parent
local storage = game:GetService('ServerStorage')
local objecttoclone = storage:WaitForChild('Capsule')

local function onUse()
	local clone = objecttoclone:Clone()
	clone.Parent = workspace
	clone:PivotTo(generator:GetPivot())
end

local function cChange()
	local topband = objecttoclone.TopCap.Band
	local bottomband = objecttoclone.BottomCap.Band
	local base = objecttoclone.BottomCap.Base
	local setto = BrickColor.random()
	topband.BrickColor = setto
	bottomband.BrickColor = setto
	base.BrickColor = setto
end

while true do
	wait(10)
	cChange()
	onUse()
end

Try this :smile:
It’s using :PivotTo() and :GetPivot()

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.