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: Random Event not working

Previous Thread :: Next Thread 
gamebuildinguy is not online. gamebuildinguy
Joined: 13 Jul 2012
Total Posts: 15
16 Jul 2012 03:21 PM
Output gave me nothing, so I was left to assume that one of my checks was failing right? So I took them out but I put prints in here, and where it failed (looking only at the bronze one as they are basically all the same) it failed when it went to check if enchant == X. I had it print echant, and the value returned as either 1,2,3,4 like planned, but I had a check after the if enchant == X and it never printed. Is there an error within that? I simply am lost.

local alert = script.Parent.Parent.alertem
local gems = script.Parent.Parent.Parent.Parent.Parent:findFirstChild("SoulGems")
function onClicked()
local bronzea = script.Parent.Parent.Parent.Parent.Parent.Backpack:findFirstChild("BronzeSword")
if bronzea == nil then return end
if gems.Value > 0 then
gems.Value = gems.Value - 1
alert.Text = "Crafting Sword."
wait(1)
alert.Text = "Crafting Sword.."
wait(1)
alert.Text = "Crafting Sword..."
wait(1)
alert.Text = "Sword Crafted!"
enchant = math.random(4)
if enchant == 0 then
alert.Text = "The gem broke!"
wait(1)
alert.Text = "Craft another Sword"
if enchant == 1 then
fa = bronzea:findFirstChild("Fire")
fa = true
alert.Text = "Fire Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
if enchant == 2 then
fab = bronzea:findFirstChild("Ice")
fab = true
alert.Text = "Ice Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
if enchant == 3 then
fad = bronzea:findFirstChild("Poisen")
fad = true
alert.Text = "Poisen Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
if enchant == 4 then
faa = bronzea:findFirstChild("Power")
faa = true
alert.Text = "Power Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
end
end
end
end
end
end
end
script.Parent.MouseButton1Click:connect(onClicked)
Report Abuse
gamebuildinguy is not online. gamebuildinguy
Joined: 13 Jul 2012
Total Posts: 15
16 Jul 2012 03:49 PM
bump - please help
Report Abuse
liavt is not online. liavt
Joined: 12 Mar 2009
Total Posts: 1241
16 Jul 2012 03:50 PM
all your findfirstchilds should be FindFirstChild not findFirstChild
Report Abuse
Techwiz19 is not online. Techwiz19
Joined: 30 Jan 2011
Total Posts: 462
16 Jul 2012 03:51 PM
it should be
math.random(1,4)
Report Abuse
gamebuildinguy is not online. gamebuildinguy
Joined: 13 Jul 2012
Total Posts: 15
16 Jul 2012 03:52 PM
Ill try that tech, and it doesn't matter if you use findFirstChild or FindFirstChild, they execute the same.
Report Abuse
gamebuildinguy is not online. gamebuildinguy
Joined: 13 Jul 2012
Total Posts: 15
16 Jul 2012 03:57 PM
The result is still the same, its not working :/
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
16 Jul 2012 04:18 PM
It doesn't need to be math.random(1,4) because if you give only one argument then it will assume that the starting number is 1 and find an integer between 1 and the number you give, inclusive. If you give no arguments, it will find a random decimal between 0 and 1
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
16 Jul 2012 04:21 PM
You're using this for a gui right?
Report Abuse
Jayskull900 is not online. Jayskull900
Joined: 26 Nov 2006
Total Posts: 590
16 Jul 2012 04:22 PM
Yes, he is. But I don't see how your reply makes sense.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
16 Jul 2012 04:34 PM
http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions#math.random
Report Abuse
Jayskull900 is not online. Jayskull900
Joined: 26 Nov 2006
Total Posts: 590
16 Jul 2012 04:37 PM
Let me rephrase, I know what you mean, I'm saying that won't fix the issue.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
16 Jul 2012 04:39 PM
Right but I was just pointing it out to him.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
16 Jul 2012 04:41 PM
if enchant == 0 then
math.random(4) will never equal 0, so instead just change enchant to
enchant = math.random(5)
and then change the top line up there to
if enchant == 5 then
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
16 Jul 2012 04:43 PM
also change all the
if enchant == #
to
elseif enchant == #
and remove the ends that were used for the if's
we change them to elseif because that way only 1 is selected, but if there are 5 if statements all 5 of them could end uo being true, because you are doing a different math.random for each one
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
16 Jul 2012 04:47 PM
try this

local alert = script.Parent.Parent.alertem
local gems = script.Parent.Parent.Parent.Parent.Parent:findFirstChild("SoulGems")
function onClicked()
local bronzea = script.Parent.Parent.Parent.Parent.Parent.Backpack:findFirstChild("BronzeSword")
if bronzea == nil then return end
if gems.Value > 0 then
gems.Value = gems.Value - 1
alert.Text = "Crafting Sword."
wait(1)
alert.Text = "Crafting Sword.."
wait(1)
alert.Text = "Crafting Sword..."
wait(1)
alert.Text = "Sword Crafted!"
enchant = math.random(5)
if enchant == 5 then
alert.Text = "The gem broke!"
wait(1)
alert.Text = "Craft another Sword"
elseif enchant == 1 then
fa = bronzea:findFirstChild("Fire")
fa = true
alert.Text = "Fire Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
elseif enchant == 2 then
fab = bronzea:findFirstChild("Ice")
fab = true
alert.Text = "Ice Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
elseif enchant == 3 then
fad = bronzea:findFirstChild("Poisen")
fad = true
alert.Text = "Poisen Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
elseif enchant == 4 then
faa = bronzea:findFirstChild("Power")
faa = true
alert.Text = "Power Sword Crafted!"
wait(1)
alert.Text = "Craft another sword"
end
end
end
script.Parent.MouseButton1Click:connect(onClicked)
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