Help with Tween Service script

Hello.

So, I am trying to make an orb that will fall from the sky every 15 minutes. I’m new to TweenService so I need some help. I don’t know how to make it so if a player touches the orb. It disappears 7 seconds after the collision with a player. Would this be a script in the Orb or part of this script?

Here’s the script!:

local previousSpawnPoint
local orb = game.ServerStorage.Orb 
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new() 

while true do

   task.wait(15 * 60) -- Waits 15 minutes
   local chosenSpawn = spawnLocations:GetChildren[math.random(1, #spawnLocations:GetChildren())]  
  

   if previousSpawn ~= nil and previousSpawn == chosenSpawn then 
     
           chosenSpawn = spawnLocations:GetChildren[math.random(1, #spawnLocations:GetChildren())] 
       until chosenSpawn ~= previousSpawn
    end
       previousSpawn = chosenSpawn

       local orbClone = orb:Clone
       orbClone.Parent = workspace
       orbClone.Position = chosenSpawn.Position + Vector3.new(0, chosenSpawn.Position.Y + 20, 0)
       tweenService:Create(orbClone, tweenInfo, {
         Position = chosenSpawn.Position}):Play()
end

Could someone help?

2 Likes

Okay!
You could’ve continued this in your original post but hey ho here we are.

Please do some research on the roblox wiki it is a great place to start!

TweenInfo - link
TweenService - link

I’ve adjusted your script to include a time variable as the first parameter in tweeninfo, and a easingstyle of sine.

local previousSpawnPoint
local orb = game.ServerStorage.Orb 
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new() 

while true do

   task.wait(15 * 60) -- Waits 15 minutes
   local chosenSpawn = spawnLocations:GetChildren[math.random(1, #spawnLocations:GetChildren())]  
  

   if previousSpawn ~= nil and previousSpawn == chosenSpawn then 
     
           chosenSpawn = spawnLocations:GetChildren[math.random(1, #spawnLocations:GetChildren())] 
       until chosenSpawn ~= previousSpawn
    end
       previousSpawn = chosenSpawn

       local orbClone = orb:Clone
       orbClone.Parent = workspace
       orbClone.Position = chosenSpawn.Position + Vector3.new(0, chosenSpawn.Position.Y + 20, 0)
       tweenService:Create(orbClone, tweenInfo, {
         Position = chosenSpawn.Position}):Play()
end

Now to tackle the second thing,
5 minutes is 5*60 (5 minutes) etc idk how to explain im horrible!

One way to accomplish this is to use our handy dandy touched event.

I have once again edited your script to do this for you.

``lua
local previousSpawnPoint
local orb = game.ServerStorage.Orb
local tweenService = game:GetService(“TweenService”)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine)
local previousSpawn = nil
local spawnLocations = nil --// if the variable exists remove else set this to your spawnpoints

while true do
task.wait(15 * 60) – Waits 15 minutes
local chosenSpawn = spawnLocations:GetChildren()[math.random(1, #spawnLocations:GetChildren())]
if previousSpawn ~= nil and previousSpawn == chosenSpawn then
repeat task.wait()
chosenSpawn = spawnLocations:GetChildren()[math.random(1, #spawnLocations:GetChildren())]
until chosenSpawn ~= previousSpawn
previousSpawn = chosenSpawn

	local orbClone = orb:Clone()
	orbClone.Parent = workspace
	orbClone.Position = chosenSpawn.Position + Vector3.new(0, chosenSpawn.Position.Y + 20, 0)
	tweenService:Create(orbClone, tweenInfo, {Position = chosenSpawn.Position}):Play()
	local orbCollected = false
	local start = tick()
	local hitConn
	
	hitConn = orbClone.Touched:Connect(function(hit)
		if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if player then
				--// award badge if you want
				orbCollected = true
				hitConn:Disconnect()
			end
		end
	end)
	
	repeat task.wait() until orbCollected or (tick() - start) >= 5*60
	if hitConn then
		hitConn:Disconnect()
	end
	hitConn = nil
	tweenService:Create(orbClone, tweenInfo, {Transparency = 1}):Play()
	game.Debris:AddItem(orbClone, tweenInfo.Time + .5)
end	

end

i myself have not played tsb before but this script should be more then enough than you need to help you.
Also here’s the link to badgeservice!

1 Like

I probably ought to explain tick.
tick is seconds since january 1970 afaik.

you can use tick for timers!
tick is ALWAYS increasing so if you store a tick in a variable then later on if you do tick() - start or variable then you will get seconds since that stored tick which is now a timer! :smiley:

HITCONN is not needed but I thought I’d throw it in to prevent memory leaks because you can never trust roblox that much…

Thank you! However your script seems a bit broken in your reply.

Okay!
Do me a favour and open the ‘output’ go to the top bar of your studio window, → View → Output
Then go ingame and send me a lovely screenshot of your entire studio window so i can see what is erroring.

If its the syntax highlighting don’t worry just copy the entire script there is a extra end I’m going to attempt to fix it hold on.

local previousSpawnPoint
local orb = game.ServerStorage.Orb 
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine) 
local previousSpawn = nil
local spawnLocations = nil --// if the variable exists remove else set this to your spawnpoints

while true do
	task.wait(15 * 60) -- Waits 15 minutes
	local chosenSpawn = spawnLocations:GetChildren()[math.random(1, #spawnLocations:GetChildren())]  
	if previousSpawn ~= nil and previousSpawn == chosenSpawn then 
		repeat task.wait()
			chosenSpawn = spawnLocations:GetChildren()[math.random(1, #spawnLocations:GetChildren())]  
		until chosenSpawn ~= previousSpawn
		previousSpawn = chosenSpawn

		local orbClone = orb:Clone()
		orbClone.Parent = workspace
		orbClone.Position = chosenSpawn.Position + Vector3.new(0, chosenSpawn.Position.Y + 20, 0)
		tweenService:Create(orbClone, tweenInfo, {Position = chosenSpawn.Position}):Play()
		local orbCollected = false
		local start = tick()
		local hitConn
		
		hitConn = orbClone.Touched:Connect(function(hit)
			if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if player then
					--// award badge if you want
					orbCollected = true
					hitConn:Disconnect()
				end
			end
		end)
		
		repeat task.wait() until orbCollected or (tick() - start) >= 5*60
		if hitConn then
			hitConn:Disconnect()
		end
		hitConn = nil
		tweenService:Create(orbClone, tweenInfo, {Transparency = 1}):Play()
		game.Debris:AddItem(orbClone, tweenInfo.Time + .5)
	end	
end
1 Like

Im a little confused on which script is which and where they go.

Ideally where your previous script was but if not then ServerScriptService is a good place to start.
Please see my other reply above this one for the full script with correct syntax and thingy.

I keep getting an error with line 10 with the first script. It won’t even tell me what the error is.

At the top of the script you need to fill in the spawnLocations variable so that the game know where to spawn stuff.

Also for debugging purposes I would recommend setting the task.wait(15*60) to like 6 or so.

local previousSpawnPoint
local orb = game.ServerStorage.Orb 
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine) 
local previousSpawn = nil
local spawnLocations = workspace.SpawnLocations --// if the variable exists remove else set this to your spawnpoints

while true do
	task.wait(7) -- Waits 15 minutes
	local chosenSpawn = SpawnLocations:GetChildren()[math.random(1, #SpawnLocations:GetChildren())]  
	if previousSpawn ~= nil and previousSpawn == chosenSpawn then 
		repeat task.wait()
			chosenSpawn = spawnLocations:GetChildren()[math.random(1, #spawnLocations:GetChildren())]  
		until chosenSpawn ~= previousSpawn
		previousSpawn = chosenSpawn

		local orbClone = orb:Clone()
		orbClone.Parent = workspace
		orbClone.Position = chosenSpawn.Position + Vector3.new(0, chosenSpawn.Position.Y + 20, 0)
		tweenService:Create(orbClone, tweenInfo, {Position = chosenSpawn.Position}):Play()
		local orbCollected = false
		local start = tick()
		local hitConn

		hitConn = orbClone.Touched:Connect(function(hit)
			if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if player then
					--// award badge if you want
					orbCollected = true
					hitConn:Disconnect()
				end
			end
		end)

		repeat task.wait() until orbCollected or (tick() - start) >= 5*60
		if hitConn then
			hitConn:Disconnect()
		end
		hitConn = nil
		tweenService:Create(orbClone, tweenInfo, {Transparency = 1}):Play()
		game.Debris:AddItem(orbClone, tweenInfo.Time + .5)
	end	
end

like this?

Yes if that is where your folder is.

1 Like

It works! Thank you for helping!

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