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

How to detect 2 or more StringValues in a TextButton?

Hi. I'm a beginner scripter and I am making my first game on ROBLOX. But I have a problem, I need a ready button.

Do I need a LocalScript so only the player that clicked on it can see if he/she is ready or not?

Im thinking about trying this script that I'll insert into the button. Tell me if there is a mistake.

LocalScript

script.Parent.MouseButton1Click:Connect(function() script.Parent.BackgroundColor3 = Crimson script.Parent.Text = ("Not Ready") local playerReady = Instance.new("StringValue") playerReady.Parent = script.Parent

Thats all I could think of. I need something that detects 2 or more String Values so the game can start.

3 comments

0

If you want to be a "Good Developer" I recommend you to see my answer in a question. In the next comment I'll send the Link.

0

You can detect more than 1 string value in the text of a textbutton since it only has one value

2 answers

✓ Accepted answer

Ok, lets try it!

First Step : We need to know how to use the "Instance.new()" function, so we can start our code. I'm giving you a LInk where you can read a post on the DevHub and learn how and where you can use it correctly!

Link : https://developer.roblox.com/en-us/api-reference/class/Instance

Second Step : We need to know what's exactly a "String Value"! First of all the StringValue can only store one thing! A string (text) and can be like this...

local stringV = Instance.new("StringValue", script.Parent)
stringV.Value = "This is just a string"

wait()

print(stringV.Value)

That's how we use the Instance.new() and the strings! Now how we can use tables...? (The tables make the things easier when you need to storage something!)

Third Step : Enjoy coding! You always have to enjoy what are you doing! Play some music while you script or even you can play a game so you will be relaxed!

Lets get into the code!

--> Local <--

local instances = {
    	["String Value"] = Instance.new('StringValue');
    	["String Value2"] = Instance.new('StringValue')
}

local ready = false

--> Code <--

instances["String Value"].Parent = script.Parent
instances["String Value"].Value = 'The player it doesnt ready'

instances["String Value2"].Parent = script.Parent
instances["String Value2"].Value = 'Ready... Teleporting!'

local function readyFunction() 
    	if not ready then
        	script.Parent = (instances['String Value'].Value)
        	wait() --> The wait you want
        	ready = true

    	elseif ready then
        	script.Parent = (instances['String Value2'].Value)
    	end
end

script.Parent.Text = readyFunction()

That's how we can't make the script you wanted! Is also a easy one and is completely functional!

I hope my answer already solve your question. If it does please accept my answer. That will help me a lot!

Keep scripting!

2 comments

0

you forgot .Text on line 20 and 25, also call the function on line 29 with the MouseButton1Click event.

0

Ohhh, I didn't see he has a click event.

it's very hard to read your script. If your game is filtering enabled, you'll have to fire an event in order for the server to know if the player is ready or not, and I suggest you learn how remotes work first. You can read the wiki as a starting place.

string value is not ideal in your situation, use a bool value instead, but I'll give you a brief script, you'll need to learn events for it to work fully in a filtering enabled place (this should be a local script btw):

local bool = Instance.new("BoolValue",script.Parent)
bool.Name = "PlayerReady"
bool.Value = false
script.Parent.Text = "Not Ready"
script.Parent.MouseButton1Down:Connect(function()
if script.Parent.Text == "Not Ready" then
script.Parent.Text = "Ready"
bool.Value = true
elseif script.Parent.Text == "Ready" then
script.Parent.Text = "Not Ready"
bool.Value = false
end
end)

it's not tested, so if you encountered any errors, I'd be glad to help. But I will not spoon-feed.

1 comment

0

indent your code.

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