Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Rock, Paper, Getting stuck... Can't get a correct outcome?

Asked by
porw2 6
7 years ago
Edited 7 years ago

First of all, i want to say that i'm pretty much a beginner when it comes to LUA. I've been trying to make this Rock, Paper, Scissors game, but as you probably read the title... Yeah... That's a better name for it, Isn't it? All that i need done is an outcome(in the way of draw, win, lose).

Here's the code that i am using:

button = game.Workspace.button
one = game.Workspace.Part1
two = game.Workspace.Part2
text1 = one.Text.Text
text2 = two.Text.Text
local Table = {"Rock","Paper","Scissors"}


function rps (chance)
    text1.Text = "Loading"
    text2.Text = "Loading"
    wait(0.5)
    text1.Text = "Loading."
    text2.Text = "Loading."
    wait(0.5)
    text1.Text = "Loading.."
    text2.Text = "Loading.."
    wait(0.5)
    text1.Text = "Loading..."
    text2.Text = "Loading..."
    wait(0.5)
    text1.Text = "Loading...!"
    text2.Text = "Loading...!"
    wait(0.5)
    text1.Text =(Table[math.random(#Table)])
    text2.Text =(Table[math.random(#Table)])
    wait(3)




end

button.ClickDetector.MouseClick:Connect(rps)

Many much thanks, Porw2

0
where did you put the text object? glinary 19 — 7y

2 answers

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago
Edited 7 years ago

You just have to compare text1 and text2. First you check if they are equal, that's easy, and it is always a tie. Then, each object has only one other object it can destroy; I would store this in a dictionary called "Victory". Learn about dictionaries here. Index it with choice1 to get what choice2 should be to win. Then a simple comparison. Here you go :)

button = game.Workspace.button
one = game.Workspace.Part1
two = game.Workspace.Part2
text1 = one.Text.Text
text2 = two.Text.Text
local Table = {"Rock","Paper","Scissors"}
local disp = "Loading...!"

local victory = {
    Rock = 'Scissors',
    Paper = 'Rock',
    Scissors = 'Paper'
}


function rps (chance)
    for i=4,0,-1 do
        --Always try to use a loop!
         --slowly reveal the string "disp"
        local str = string.sub(disp,1,#disp-i)
        text1.Text = str
        text2.Text = str
        wait(0.5)
    end
    --define choices
    local c1, c2 = Table[math.random(#Table)], Table[math.random(#Table)]
    text1.Text = c1
    text2.Text = c2
    wait(3)

    if c1 == c2 then
        print('Tie')
    elseif victory[c1] == c2 then
        print('One wins')
    else
        print('Two wins')
    end


end

button.ClickDetector.MouseClick:Connect(rps)

Ad
Log in to vote
-1
Answered by 7 years ago

You're error is in the rps function so here is the fix:

button = game.Workspace.button
one = game.Workspace.Part1
two = game.Workspace.Part2
text1 = one.Text.Text
text2 = two.Text.Text
local Table = {"Rock","Paper","Scissors"}


function rps (chance)
    text1.Text = "Loading"
    text2.Text = "Loading"
    wait(0.5)
    text1.Text = "Loading."
    text2.Text = "Loading."
    wait(0.5)
    text1.Text = "Loading.."
    text2.Text = "Loading.."
    wait(0.5)
    text1.Text = "Loading..."
    text2.Text = "Loading..."
    wait(0.5)
    text1.Text = "Loading...!"
    text2.Text = "Loading...!"
    wait(0.5)
    text1.Text =(Table[math.random(1, #Table)]) -- the first argument is always the start number and the second is always the end number keep that in mind for randomizing next time
    text2.Text =(Table[math.random(1, #Table)])
    wait(3)




end

button.ClickDetector.MouseClick:Connect(rps)

0
math.random() uses 1 as the start by default; no need to change it. cabbler 1942 — 7y

Answer this question