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

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

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

1 comment

0

where did you put the text object?

2 answers

✓ Accepted answer

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)

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)

1 comment

0

math.random() uses 1 as the start by default; no need to change it.

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