How to do this event?

Hey fellow developers!
I would like to know how to make a event that happens at a random time.
The event is that a island grows/shrinks
can you help me?
Thx for reading!

3 Likes

How to call a function repetitively at random intervals:

while true do
   wait(math.random(0.1, 30)) --You can change these bounds
   doEvent() --This can be the function you would like to run
end

How to schedule an event to happen at a random time:

function scheduleEvent()
   wait(math.random(0.1, 300)) --Again, you can change these bounds
   doEvent()
end

Not exactly sure if this is what you’re asking for. Clarify if I’m not on the right track

1 Like

k but how can i make that the island grows/shrinks

1 Like

I mean… what is your island? Is is just a single Part or MeshPart? Is it built out of Terrain?

1 Like

its a model made out of three meshparts

1 Like

Alright, so you’re going to want to change the Size property of each meshpart. You can do this multiple ways but two of the simpler solutions would be to shrink by a constant number or shrink by a constant percentage.

  • Shink a part by a constant number:
part.Size = part.Size - Vector3.new(1,1,1) --You can change these values
  • Shrink a part by a percentage:
part.Size = 0.95 * part.Size --You can change the factor out front. current shrinks by 5% each time this line would be executed.

Shrink by percentage might be the route you want to go as it would maintain aspect ratio of the part

thx and what is the whole script for the event and size change?

Well i mean I can’t fill everything in for you because I don’t know how you have everything set up… It would be something like:

local loopsCompleted = 0
while loopsCompleted < 50 do --Change the 50 if you want. This code will loop 50 times currently
wait(math.random(1,30))
island1.Size = 0.95 * island1.Size
--Do this for the other islands too
loopsCompleted = loopsCompleted + 1
end

Also,
Roblox Quick Start
This might be a helpful place to start to learn scripting. Feel free to message me directly if you have questions about the guide.

so the script is

local loopsCompleted = 0
while loopsCompleted < 50 do --Change the 50 if you want. This code will loop 50 times currently
wait(math.random(1,30))
island1.Size = 0.95 * island1.Size
--Do this for the other islands too
loopsCompleted = loopsCompleted + 1
end

but the wait(math.random(1,30)) is that it waits something between 1 and 30 seconds?

Edit: but how does it detect the island i have i1-i9 located in workspace
should i do island1 =game.Workspace.islands.i1?
(islands is a folder)

uh i did this and it doesnt work:

local loopsCompleted = 0
local island1 = game.Workspace.islands.i1
local island2 = game.Workspace.islands.i2
local island3 = game.Workspace.islands.i3
local island4 = game.Workspace.islands.i4
local island5 = game.Workspace.islands.i5
local island6 = game.Workspace.islands.i6
local island7 = game.Workspace.islands.i7
local island8 = game.Workspace.islands.i8
local island9 = game.Workspace.islands.i9

while loopsCompleted < 50 do 
	wait(math.random(1,10))
	island1.Size = 0.95 * island1.Size
	loopsCompleted = loopsCompleted + 1
	island2.Size = 0.95 * island2.Size
	loopsCompleted = loopsCompleted + 1
	island3.Size = 0.95 * island3.Size
	loopsCompleted = loopsCompleted + 1
	island4.Size = 0.95 * island4.Size
	loopsCompleted = loopsCompleted + 1
	island5.Size = 0.95 * island5.Size
	loopsCompleted = loopsCompleted + 1
	island6.Size = 0.95 * island6.Size
	loopsCompleted = loopsCompleted + 1
	island7.Size = 0.95 * island7.Size
	loopsCompleted = loopsCompleted + 1
	island8.Size = 0.95 * island8.Size
	loopsCompleted = loopsCompleted + 1
	island9.Size = 0.95 * island9.Size
	loopsCompleted = loopsCompleted + 1
end

@East98

local shrink = false

while wait(math.random(1,100)) do
	if shrink == false then
		for _,v in pairs(workspace.islands:GetChildren()) do
			if v:IsA("BasePart") then
				game.TweenService:Create(v,TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out),
					{Size = Vector3.new(0,0,0)}):Play()
				shrink = true
			end
		end
	else
		for _,v in pairs(workspace.islands:GetChildren()) do
			if v:IsA("BasePart") then
				game.TweenService:Create(v,TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out),
					{Size = Vector3.new(original_size,original_size,original_size)}):Play()
				shrink = false
			end
		end
	end
end

This is an easier but possibly more complex way of doing it.

shrink variable determines if the island has shrank or not. It is used because checking by size is somewhat unreliable. You can also modify the math.random(1,100) to a new min and max to your likings. And please change the original_size to the island’s original size since I do not know what the original size is.

You can also modify the 1 and Enum.EasingStyle.Linear and Enum.EasingDirection.Out in TweenInfo.new()

  • 1 can be replaced by any number, as it is the seconds used to finish the growing/shrinking animation.
  • You can find more about EasingStyle and EasingDirection in developer.roblox.com by searching it up.

This script only works if the islands have the same size, (because it will make every islands the same size determined by original_size) if the islands have different size, you may have to tween them one by one.

One by one script
local shrink = false

while wait(math.random(1,100)) do
	if shrink == false then
		game.TweenService:Create(workspace.island.island1,TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out),
			{Size = Vector3.new(0,0,0)}):Play()
		shrink = true
	else
		game.TweenService:Create(workspace.island.island1,TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out),
			{Size = Vector3.new(original_size,original_size,original_size)}):Play()
		shrink = false
	end
end

(Do island1, island2, island3 and so on by yourself)

Unless you have experience in something like this, you may not touch anything else other than what I have said to be safe to modify.

(This is a dirty workaround since I am no expert when it come to scripting so until any other professional arrive, you can use this.)

thx alot but it should also grow…

uh it does work… please help me?