Need help with experimental game

I was making a mini project, while i was making this script, i noticed that the random spawn generator was working, but not the way i wanted it to work.

How i wanted it to work was so that everytime it generates a new position after the first block has spawned.

Randomnumber = math.random(1,750)


while true do
	wait()
	goldplate = Instance.new("Part",game.Workspace)
	goldplate.Position = Vector3.new(Randomnumber,Randomnumber,Randomnumber)
	goldplate.BrickColor = BrickColor.new("Gold")
	goldplate.Anchored = false
	goldplate.Material = "Metal"
	wait(4.5)
end

You need to create a new random number everytime you set the position. Otherwise, it’s always the same number?

1 Like

Yeah, but im new to coding, didnt quite figure how to do that.

goldplate.Position = Vector3.new(math.random(1,750),math.random(1,750),math.random(1,750))

Just had to move the variable:

while true do
	local randompos = math.random(1,750)
	local goldplate = Instance.new("Part",game.Workspace)
	goldplate.Position = Vector3.new(randompos,randompos,randompos)
	goldplate.BrickColor = BrickColor.new("Gold")
	goldplate.Anchored = false
	goldplate.Material = "Metal"
	task.wait(4.5)
end
1 Like

Thank you., I saw that you used task.wait, could you refresh my mind a bit?

task.wait() is just more reliable than wait(). It can withstand lag and still wait the correct amount. Naturally, it will be slightly faster than the older method.

Ah, thank you, will continue on learning, thanks alot.

1 Like

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