In my script when I click the image label it should pick between 2 images(I am going to add more). But it only ever picks the first option and never the second. Any reason why ??
plr = script.Parent.Parent.Parent.Parent.Parent income = script.Parent.income local choosepunch =math.random(1,2) --1053468311 -- hitleft --1053474997 -- hitright script.Parent.MouseButton1Click:connect(function() plr.leaderstats.Hits.Value = plr.leaderstats.Hits.Value + income.Value if choosepunch==1 then script.Parent.Parent.Parent.HitRight.Visible= false script.Parent.Parent.Visible= false wait(.5) script.Parent.Parent.Parent.HitRight.Visible= true script.Parent.Parent.Visible= true wait(.5) elseif choosepunch== 2 then script.Parent.Parent.Parent.HitLeft.Visible= false script.Parent.Parent.Visible= false wait(.5) script.Parent.Parent.Parent.HitLeft.Visible= true script.Parent.Parent.Visible= true wait(.5) end end)
ChoosePunch is only defined once every game. You want it to chose another number every time clicked. Do the following
plr = script.Parent.Parent.Parent.Parent.Parent income = script.Parent.income --1053468311 -- hitleft --1053474997 -- hitright math.randomseed(tick() - wait() % wait() ^ wait()) --just some randomseed to randomize math.randoms script.Parent.MouseButton1Click:connect(function() local choosepunch = math.random(1, 2) plr.leaderstats.Hits.Value = plr.leaderstats.Hits.Value + income.Value if choosepunch==1 then script.Parent.Parent.Parent.HitRight.Visible= false script.Parent.Parent.Visible= false wait(.5) script.Parent.Parent.Parent.HitRight.Visible= true script.Parent.Parent.Visible= true wait(.5) elseif choosepunch== 2 then script.Parent.Parent.Parent.HitLeft.Visible= false script.Parent.Parent.Visible= false wait(.5) script.Parent.Parent.Parent.HitLeft.Visible= true script.Parent.Parent.Visible= true wait(.5) end end)
Remember, variables get affected by where they are placed.
Hope this helps!
Believe it or not, math.random isn't actually random! math.random() produces an equal sequence of numbers according to its seed.
For example, if you have played Minecraft, you've probably seen the option that allows you to put a seed in for your world. Minecraft worlds with the same seed have completely identical worlds.
You can set a new seed every time the game starts by doing math.randomseed(tick())
. This sets a seed for the pseudo-random generator.
This should do the trick, hope this helps!
math.randomseed(tick()) plr = script.Parent.Parent.Parent.Parent.Parent income = script.Parent.income --1053468311 -- hitleft --1053474997 -- hitright math.randomseed(tick() - wait() % wait() ^ wait()) --just some randomseed to randomize math.randoms script.Parent.MouseButton1Click:connect(function() local choosepunch = math.random(1, 2) plr.leaderstats.Hits.Value = plr.leaderstats.Hits.Value + income.Value if choosepunch==1 then script.Parent.Parent.Parent.HitRight.Visible= false script.Parent.Parent.Visible= false wait(.5) script.Parent.Parent.Parent.HitRight.Visible= true script.Parent.Parent.Visible= true wait(.5) elseif choosepunch== 2 then script.Parent.Parent.Parent.HitLeft.Visible= false script.Parent.Parent.Visible= false wait(.5) script.Parent.Parent.Parent.HitLeft.Visible= true script.Parent.Parent.Visible= true wait(.5) end end)