generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Help with math.random?

Previous Thread :: Next Thread 
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 08:46 PM
local ads = {
['Ad here!'] = true;
['Advertizement here!'] = true;
['Another ad here!'] = true
}

while wait() do
local currentad = ads[math.random(1, #ads)]
script.Parent.TextLabel.Text = currentad
script.Parent:TweenSize(1, 0, 1, 0, "out", "Quad", 2 , true)
wait(5)
script.Parent:TweenSize(0, 0, 0, 0, "out", "Quad", 2 , true)
end

--[[Got this error...
21:38:28.277 - Workspace.Part.SurfaceGui.Frame.Script:7: bad
argument #2 to 'random' (interval is empty)
--]]
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 09:09 PM
b1
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 09:15 PM
b2 I know someone out there knows how to fix this.. Please help...
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
01 Mar 2014 09:17 PM
#ads is 0.
The length operator doesn't count dictionary entries.
You could modify its metatable to do this, though.



setmetatable(ads, {__len = function(t) local i = 0 for _, v in pairs(t) do i = i + 1 end return i end})


Put that under the definition of your ads table.
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
01 Mar 2014 09:21 PM
local ads = {['Ad here!'],['Advertizement here!'],['Another ad here!']}
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
01 Mar 2014 09:23 PM
Woops.
You implementation would require the above post, not mine.

Sorry!
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 09:23 PM
local ads = {
['Ad here!'] = 1;
['Advertizement here!'] = 2;
['Another ad here!'] = 3
}

while wait() do
local currentad = ads[math.random(1, #ads)]
script.Parent.TextLabel.Text = currentad
script.Parent:TweenSize(1, 0, 1, 0, "out", "Quad", 2 , true)
wait(5)
script.Parent:TweenSize(0, 0, 0, 0, "out", "Quad", 2 , true)
end


Agent would this also work?
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
01 Mar 2014 09:32 PM
you don't need to index them as 1,2,3
they are indexed themselves
like I said:
local ads = {'Ad here!','Advertizement here!','Another ad here!'}
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 09:44 PM
Island I tried that I got the error that I needed a '=' after ','.. I tried putting a = after comma and I got the origional error.
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
01 Mar 2014 09:46 PM
ads = {"ad here!","ad number 2!","yello!ima ad:3"}
currentad = ads[math.random(1,#ads)]
print (currentad)
ur doing something rong,this works
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 09:48 PM
@Island I tried the new one now it changes the text to a number...
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
01 Mar 2014 09:50 PM
you are really messin up here..
post your current script
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 09:50 PM
Nevermind Thanks.
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
01 Mar 2014 10:07 PM
Now I'm getting this error:


Unable to cast double to UDim2 - Line 7



ads = {"ad here!","ad number 2!","yello!ima ad:3"}

while wait() do
local currentad = ads[math.random(1, #ads)]
script.Parent.TextLabel.Text = currentad
print(currentad)
script.Parent:TweenSize(1, 0, 1, 0, Out, Quad, 1, true)
wait(5)
script.Parent:TweenSize(0, 0, 0, 0, Out, Quad, 1, true)
end
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
01 Mar 2014 10:08 PM
Idk about that one..
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
01 Mar 2014 10:09 PM
First argument of TweenSize is a UDim2 value. You put numbers.
Report Abuse
juniorjfive is not online. juniorjfive
Joined: 05 Jan 2010
Total Posts: 671
01 Mar 2014 10:13 PM
>line 7
You're line 7 says :TweenSize(1, 0, 1, 0, Out, Quad, 1, true)).
How's it suppose to move if Gui's Sizes/Positions work with UDim2.new()?
Just simply add the following to line 7 and line 9:
Line7:script.Parent:TweenSize(UDim2.new(1, 0, 1, 0), 'Out', 'Quad', 1, true)
Line9:script.Parent:TweenSize(UDim2.new(0, 0, 0, 0), 'Out', 'Quad', 1, true)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image