Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i fix my Gui Script???

I have a Gui and what i does is when you enter the game is say's your name, Hello('Player') then it say's how old your account is in years and days. The problem is when i added this code -- if years<days then textLabel.Text=years+1 -- what it's suppose to do is when the account age in days get passed 365 it rounds the years up 1 number but instead it deletes the days part and all the text and just this number pops up (7.3562534562) How do i fix this and make it work properly. If you fix this you will be my Hero forever!

game.Players.PlayerAdded:connect(function(plr)
    local screenGui = Instance.new("ScreenGui")
    screenGui.Parent = plr:WaitForChild("PlayerGui")
   
 local frame = Instance.new("Frame")
    frame.Parent = screenGui
    frame.Size = UDim2.new(1,0,1,0)
    frame.Position = UDim2.new(0,0,0,0)
    frame.BackgroundColor3 = Color3.new(0,0,0)

    local frame2 = Instance.new("Frame")
    frame2.Parent = screenGui
    frame2.Size = UDim2.new(0.9,0,0.9,0)
    frame2.Position = UDim2.new(0.05,0,0.05,0)
    frame2.BackgroundColor3 = BrickColor.White().Color
local days=plr.AccountAge
local years=days/365
    local textLabel = Instance.new("TextLabel")
	textLabel.Parent = frame2
    textLabel.Position = UDim2.new(0.05,0,0.05,0)
    textLabel.Size = UDim2.new(0.9,0,0.9,0)
    textLabel.BackgroundColor3 = BrickColor.White().Color
 	textLabel.FontSize = "Size24"
	textLabel.Text=('Hello '..plr.Name)
wait(3)
	
	textLabel.Text=('Your Account is '..years..' years old ('..days..') Days old')
if years<days then
textLabel.Text=years+1
end
end)

3 answers

✓ Accepted answer

Mmk, it was a pretty easy fix, Made it round the days/365 to the nearest digit, and it will show the days, as I used manipulating 365, which will get the remaining days after it's divided by 365.

game.Players.PlayerAdded:connect(function(plr)
    local screenGui = Instance.new("ScreenGui")
    screenGui.Parent = plr:WaitForChild("PlayerGui")

 	local frame = Instance.new("Frame")
    frame.Parent = screenGui
    frame.Size = UDim2.new(1,0,1,0)
    frame.Position = UDim2.new(0,0,0,0)
    frame.BackgroundColor3 = Color3.new(0,0,0)

    local frame2 = Instance.new("Frame")
    frame2.Parent = screenGui
    frame2.Size = UDim2.new(0.9,0,0.9,0)
    frame2.Position = UDim2.new(0.05,0,0.05,0)
    frame2.BackgroundColor3 = BrickColor.White().Color
	local accage = plr.AccountAge
	local years = math.floor(accage/365)
	local days = accage % 365
    local textLabel = Instance.new("TextLabel")
    textLabel.Parent = frame2
    textLabel.Position = UDim2.new(0.05,0,0.05,0)
    textLabel.Size = UDim2.new(0.9,0,0.9,0)
    textLabel.BackgroundColor3 = BrickColor.White().Color
    textLabel.FontSize = "Size24"
    textLabel.Text=('Hello '..plr.Name)
	wait(3)

    textLabel.Text=('Your Account is '..years..' years old ('..days..') Days old')
end)


Otherwise, the script is fine! Hope this helped :D

4 comments

0

Crap, ya beat me to it xD Upvoted

0

Lol, :P

0

On years it say's 0 and that's not true

0

I edited it, try refreshing, I had something wrong, but i noticed it quickly and fixed it.

You need to first get rid of the extra days, so that it can be divided evenly into years. To do this we'll need to find the days and the years by doing this:

local daysExtra = plr.AccountAge%365 --Finds the amount of extra days after an even amount of years
local days = daysExtra --Sets it to the amount of extra days
local years = (plr.AccountAge-daysExtra)/365 --Divides the amount of days minus extra days, by 365 to get the total amount of years.

Now, if we put this into the code correctly, it should look like this:

game.Players.PlayerAdded:connect(function(plr)
    local screenGui = Instance.new("ScreenGui")
    screenGui.Parent = plr:WaitForChild("PlayerGui")
 	local frame = Instance.new("Frame")
    frame.Parent = screenGui
    frame.Size = UDim2.new(1,0,1,0)
    frame.Position = UDim2.new(0,0,0,0)
    frame.BackgroundColor3 = Color3.new(0,0,0)
    local frame2 = Instance.new("Frame")
    frame2.Parent = screenGui
    frame2.Size = UDim2.new(0.9,0,0.9,0)
    frame2.Position = UDim2.new(0.05,0,0.05,0)
    frame2.BackgroundColor3 = BrickColor.White().Color
	local daysExtra=plr.AccountAge%365
	local days=plr.AccountAge
	local years=(plr.AccountAge-daysExtra)/365
    local textLabel = Instance.new("TextLabel")
    textLabel.Parent = frame2
    textLabel.Position = UDim2.new(0.05,0,0.05,0)
    textLabel.Size = UDim2.new(0.9,0,0.9,0)
    textLabel.BackgroundColor3 = BrickColor.White().Color
    textLabel.FontSize = "Size24"
    textLabel.Text=('Hello '..plr.Name)
	wait(3)
	textLabel.Text=('Your Account is '..years..' years old ('..days..' Days old)')
end)

Anyways, the code should work now. If you have any problems/questions, please leave a comment below. Hope I helped :P

3 comments

0

Didn't work, all that popped up was a 7

0

Yea sorry, that last bit of code you put messed me up. It should work now.

0

Thanks i already fixed it though

game.Players.PlayerAdded:connect(function(plr)
    local screenGui = Instance.new("ScreenGui")
    screenGui.Parent = plr:WaitForChild("PlayerGui")
   
 local frame = Instance.new("Frame")
    frame.Parent = screenGui
    frame.Size = UDim2.new(1,0,1,0)
    frame.Position = UDim2.new(0,0,0,0)
    frame.BackgroundColor3 = Color3.new(0,0,0)

    local frame2 = Instance.new("Frame")
    frame2.Parent = screenGui
    frame2.Size = UDim2.new(0.9,0,0.9,0)
    frame2.Position = UDim2.new(0.05,0,0.05,0)
    frame2.BackgroundColor3 = BrickColor.White().Color
local days=plr.AccountAge
local years=days/365
    local textLabel = Instance.new("TextLabel")
	textLabel.Parent = frame2
    textLabel.Position = UDim2.new(0.05,0,0.05,0)
    textLabel.Size = UDim2.new(0.9,0,0.9,0)
    textLabel.BackgroundColor3 = BrickColor.White().Color
 	textLabel.FontSize = "Size24"
	textLabel.Text=('Hello '..plr.Name)
wait(3)
	
	
local years = 0
for i = 1, days/365.25 do
years = years + 1
days = days - 365.25
end
textLabel.Text=('You are: '..years..' year(s) and '..days..' days old')
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.