closed and already solved sorry
Ok if you are new its a little bit complicated but no problem,
- Create a new ScreenGui
- Create a Frame size to 1,0,1,0
- Create the first lable position = 0.5,0,0.2,0 Play with the properties and change teh text to You`ve found…
- Create for each State a Textbox in a Frame rename Common,Legendary …
- Create a local script inside then set the first frame to Visible = fals
- Create a funktion and a for loop set the amount of loops how many states do you want to show
- Next Create a random value between 1 and the amound of States in the For loop
- Then Choose one of you states with the random number
- Create a Tweenservice
- Make the state Visibel
- Play Tween
- Make the state invisible
- Add Sound Clickern
13.Outside the for loop copy paste the code but this time show only one this is you result
hope that helps
Use TweenService to get that Text movement, and create a custom TweenInfo, which will determine how the text will move.
local TweenService = game:GetService("TweenService")
local TextMovementAnimation = TweenInfo.new(
0.5, -- How long the tween should be
Enum.EasingStyle.Sine, -- The type of easing style
Enum.EasingDirection.Out -- The type of easing direction
)
Now, let’s create a function that handles rolling the text. We first get the text object, position it away from the center a little bit, and then using TweenService and TweenInfo, animate the text’s movement. TextObject
should have the AnchorPoint property set to 0.5, 0.5
local function Roll()
TextObject.Position = UDim2.new(0.5, 0, 0.4, 0) -- Set the Default Position
TweenService:Create(
TextObject, -- The object to tween
TextMovementAnimation, -- The TweenInfo that was given
{
Position = UDim2.new(0.5, 0, 0.5, 0) -- The position
} -- The properties to change
):Play() -- Plays the tween
end
In the video provided, the rolling animation happens a few times. So we can wrap everything inside that function into a loop. We can also edit the TextObject to change the text as well using math.random
and a table. We also need to add a delay so that they don’t happen simultaneously.
local items = {
"Common",
"Uncommon",
"Rare",
"Legendary"
} -- The items that the text will randomly choose from
local function Roll()
for _ = 1, 5 do -- Change 5 to how many times you want the animation to happen
TextObject.Text = items[math.random(1, #items)] -- Gets a random item from items and sets that as the text
TextObject.Position = UDim2.new(0.5, 0, 0.4, 0)
local tween = TweenService:Create(TextObject, TextMovementAnimation, {Position = UDim2.new(0.5, 0, 0.5, 0)})
tween:Play()
tween.Completed:Wait() -- Wait until the tween is finished
end
end
Full code:
local TweenService = game:GetService("TweenService")
local TextMovementAnimation = TweenInfo.new(
0.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out
)
local items = {
"Common",
"Uncommon",
"Rare",
"Legendary"
}
local function Roll()
for _ = 1, 5 do
TextObject.Text = items[math.random(1, #items)]
TextObject.Position = UDim2.new(0.5, 0, 0.4, 0)
local tween = TweenService:Create(TextObject, TextMovementAnimation, {Position = UDim2.new(0.5, 0, 0.5, 0)})
tween:Play()
tween.Completed:Wait()
end
end
im an absolute idiot for not analyzing your topic further. math.random will be your best friend for this
woah thanks sweet code can i try your code soo i can see what i am doijng lol
Sure, you can use my code for your rolling system.
Note you do have to define the TextObject
variable as it is nowhere in the code provided.
Omg thank you let me try your idea this is great really amazing.
Thank you but does this actually work in a rarity kind of thing like in percentage bc i get legendary every time.
The items
list has 4 values, so each value would be a 25% chance. We could decrease the chances by adding a percentage value for each item like so:
local items = {
{"Common", 100}, -- 100%
{"Uncommon", 75}, -- 75%
{"Rare", 25}, -- 25%
{"Legendary", 10} -- 10%
}
Then we could add a function that determines the type of item you’ll get.
local function DetermineItemOnNumber(number)
local currentItem
for _, item in items do
if number > item[2] then continue end -- Skip this item if the number is greater than the range
if currentItem then
if item[2] > currentItem[2] then continue end -- Skip this item if it is more common than the currentItem
end
currentItem = item
end
return currentItem
end
Now edit the Roll()
function.
local function Roll()
for _ = 1, 5 do
local item = DetermineItemOnNumber(math.random(0, 100)) -- Get the item
TextObject.Text = item[1] -- Set the text
TextObject.Position = UDim2.new(0.5, 0, 0.4, 0)
local tween = TweenService:Create(TextObject, TextMovementAnimation, {Position = UDim2.new(0.5, 0, 0.5, 0)})
tween:Play()
tween.Completed:Wait()
end
end
Full Code:
local TweenService = game:GetService("TweenService")
local TextMovementAnimation = TweenInfo.new(
0.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out
)
local items = {
{"Common", 100},
{"Uncommon", 75},
{"Rare", 25},
{"Legendary", 10}
}
local function DetermineItemOnNumber(number)
local currentItem
for _, item in items do
if number > item[2] then continue end
if currentItem then
if item[2] > currentItem[2] then continue end
end
currentItem = item
end
return currentItem
end
local function Roll()
for _ = 1, 5 do
local item = DetermineItemOnNumber(math.random(0, 100))
TextObject.Text = item[1]
TextObject.Position = UDim2.new(0.5, 0, 0.4, 0)
local tween = TweenService:Create(TextObject, TextMovementAnimation, {Position = UDim2.new(0.5, 0, 0.5, 0)})
tween:Play()
tween.Completed:Wait()
end
end
WOah serious code there thanks bro.
Sorry for the off-topic, but what game is this? I am just curious. Also make sure to mark that reply a solution if it works.
just rolling stuff and getting stuff i just wawnt to learn how to code well soo i am making this
Cool, but I was asking for the game in the video, my bad.
Eh every real Programer thinks he knows nothing about programing, Only when we compare to noknown other people we reconize that we are not that bad as we thought.You are not a good programmer if you think you are the best in the room. Everyone is learning, like me and you.
Have a nice day
I think you misunderstood me i ment that you are not an Idiot,
my bad then. you could have replied to my second post because i have a slow brain
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.