What I want to do is for the script to pick a number from 1 to a number in a variable (the max the variable can hold is 4, set by me) and if the script chooses 1, 2, 3 or 4, those numbers are a specific part, and the script's Parent (which is a Part
) is moved to the position given in the position of the planet chose by the script. When the part (called Meteor) reaches its destination, it takes away the health of a part. (I got that covered, and the moving part as well)
My Code:
local NumOfPlanets = workspace.PlanetsStorageAndInfo.PurchasedPlanets local PlanetDestination = script.Parent.DestinationPosition --Value can go to a max of 4 local PlanetNumVar = script.Parent.PlanetNumCode local TimeTillNextLaunch = nil --Idk if this means "0" while true do math.randomseed(tick()) PlanetNumVar.Value = math.random(1, NumOfPlanets.Value) workspace.MeteorDestination.Parent = script.Parent script.Parent.Anchored = false --[[ If the Script chooses "1", It fires the meteor at the default planet. If the Script chooses "2", It fires the meteor at the 2nd purchased planet. If the Script chooses "3", It fires the meteor at the 3rd purchased planet. If the Script chooses "4", It fires the meteor at the 4th purchased planet. --]] if PlanetNumVar.Value == 1 then script.Parent.MeteorDestination.Position = workspace.Planet.PlanetBall.Position script.Parent.MeteorDestination.LocateImpact.Disabled = false end if PlanetNumVar.Value == 2 then script.Parent.MeteorDestination.Position = workspace.PlanetPlacement.Position script.Parent.MeteorDestination.LocateImpact.Disabled = false end if PlanetNumVar.Value == 3 then script.Parent.MeteorDestination.Position = workspace.PlanetPlacement2.Position script.Parent.MeteorDestination.LocateImpact.Disabled = false end if PlanetNumVar.Value == 4 then script.Parent.MeteorDestination.Position = workspace.PlanetPlacement3.Position script.Parent.MeteorDestination.LocateImpact.Disabled = false end PlanetNumVar.Value = nil TimeTillNextLaunch = math.random(35, 95) wait(TimeTillNextLaunch) end
The TimeTillNextLaunch
is when the script is gonna repeat the actions, it waits the amount of seconds set by the script. The MeteorDestination
seen on Line 9 is a BodyForce
, used to move the part.
PLEASE ANSWER IN AN ANSWER, NOT A COMMENT.
Thank you!