How to create an item spawner with random colors?

So I built a soda machine, and what I want it to do is on a button press is spawn a can model in one of the three colors in there at the ‘dispenser’ and have it roll around a bit. (maybe I’ll make it a tool eventually but one thing at a time)

I’m loading a model, so I’m using loadasset, but I’m wondering if there’s a better way to do this. Since it’s. Y’know. Not working. lmao

This is my server script

local canEvent = game.ReplicatedStorage:WaitForChild("CanSpawn")
local machine = workspace:WaitForChild("soda pawp")

--canColors = {1001,330,226}--

--[[local canColor = math.randomseed(tick())
	local colorPick = canColors[math.random(1,#canColors)]
	]]--


canEvent.OnServerEvent:Connect(function()
local canModel = game:GetService('InsertService'):LoadAsset(4769594297)
	canModel.Parent = machine.spawn
	print "event sent"
end)

and this is the local script

--[[soda pawp machine; shinyswablu]]--

local machine = workspace:WaitForChild("soda pawp")
local button = machine.button.ClickDetector
local canEvent = game.ReplicatedStorage:WaitForChild("CanSpawn")
	
	
button.MouseClick:Connect(function(player)
	canEvent:FireServer(player)
end)

I put in a random table with the three colors, but I marked it off as comment to get everything else working, and there’s just, no colors being spawned with it. Is it because I can’t call colors to something that doesn’t exist yet? I had a function under the model being spawned, so since it was after, I thought it’d be okay… Or is it the part I have set as parent?

Everything I’ve seen about loadasset is pre loading, so I’m not sure if this is even the right thing to do lmao. Any advice would be appreciated!

1 Like

I’m pretty sure the model your using has a texture on it. Textures override brick colors, Instead of using insert service just put the can model into something like replicated storage and clone it out from there.

3 Likes

It doesn’t have a texture, but I never thought of yeeting the model in there. I’ll try that out, thanks!

1 Like

Update: It worked! Thank you so much :smiley: