How is my code to create a coin spawner in a vault?

This works by being parented to the ceiling part of a vault room, where loot is occasionally generated.

local Parent, Players, Folder, Coin, Color, Value = script.Parent, game:GetService("Players"), Instance.new("Folder"), Instance.new("Part"), {BrickColor.new(360), BrickColor.new(131), BrickColor.new(333)}, {10, 60, 200}
Folder.Name, Folder.Parent, Coin.Size, Coin.Material, Coin.Shape = Parent.Name, workspace, Vector3.new(0.125, 1, 1), Enum.Material.Metal, Enum.PartType.Cylinder
local Pos = Parent.Position+Vector3.new(-16, -2, 0)
repeat
	local Coin, Num = Coin:Clone(), math.max(math.random(4)-1, 1)
	local Light, Color = Instance.new("PointLight", Coin), Color[Num]
	Light.Color, Light.Range, Coin.BrickColor, Coin.Position, Coin.Parent = Color.Color, 8, Color, Pos+Vector3.new(math.random()*32, 0, math.random()*40), Folder
	Coin.Touched:Connect(function(Part)
		local Char = Part:FindFirstAncestorOfClass("Model")
		if not Char then return end
		local Player = Players:GetPlayerFromCharacter(Char)
		if not Player then return end
		Coin:Destroy()
		local Data = shared.Data
		if not Data then return end
		Data[Player][2] += Value[Num]
	end)
	task.wait((math.random()+1)/(Players.NumPlayers+1)*120)
until nil
1 Like

Hold on ima try replicating it and giving you feedback

Actually its pretty nice, you could improve the spawn speed but it pretty nice, try anchoring the coin and adding a disabled script inside the main script and make the script rotate a part so then you clone that script and place it into the coin and enable it, and also you might wanna focus on making the coin only 1 color and if its a small area reduce the spawn radius, maybe even add some particle, and make the coin just a bit bigger and maybe make it a mesh for more detail!

I rate it a 4/5 its pretty good

1 Like

The different colors correspond to different rewards for picking up the coin. Copper = 10, Silver = 60, Gold = 200.

1 Like

Ohh sorry i thought it was all worth the same

This video should be very helpful for you. Covers the issue you are trying to solve while also helping you with better security and networking

2 Likes