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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Strings?

Previous Thread :: Next Thread 
JayTheDJ is not online. JayTheDJ
Joined: 07 Aug 2011
Total Posts: 262
12 Apr 2016 11:47 AM
deb = false

script.Parent.MouseButton1Click:connect(function()
if deb == false then
deb = true

findPlayer = game.Players:FindFirstChild(script.Parent.Parent.CNameTextBox.Text)
if findPlayer ~= nil then

-- Code Goes Here


end

wait(5)
deb = false
end
end)


So the above script basically is for a text button on my GUI. The code would work for anything I do, however there has to be a better process.

I tried deconstructing how admin scripts do this but I have no luck.

Can anyone explain the process of writing only a snippet of the string and having the script still find the player?

Ex. JayThe would find JayTheDJ still.
Report Abuse
HumanXerxes is not online. HumanXerxes
Joined: 17 Apr 2011
Total Posts: 1351
12 Apr 2016 12:00 PM
In LocalScripts, you can define the player like so:

local Player = game.Players.LocalPlayer
Report Abuse
djVas is not online. djVas
Joined: 24 Mar 2016
Total Posts: 13
12 Apr 2016 12:02 PM
You have a problem :
script.Parent.MouseButton1Click:connect(function()
you need to add a '.' Here^
Report Abuse
DoTehAlan is not online. DoTehAlan
Joined: 13 Feb 2011
Total Posts: 626
12 Apr 2016 12:03 PM
I'm not great at this type of thing but perhaps this could work:

Every time a player enters a game create a stringvalue for them and make the value equal to their name and when they leave find the value with their name and destroy it. Then for the script above I would do something like this:

for i, plrname in pairs (game.Workspace:GetChildren()) do
if plrname:IsA("StringValue") then
if string.match(plrname.Value, script.Parent.Parent.CNameTextBox.Text) ~= nil then

--do stuffs
Report Abuse
DoTehAlan is not online. DoTehAlan
Joined: 13 Feb 2011
Total Posts: 626
12 Apr 2016 12:06 PM
the string.match function, if you don't know, checks if a string contains the specified text (in this case the text in the text box).

For example:

If I said print(string.match("DoTehAlan", "Do")) it would print "Do" in the output because it is in the string, otherwise if I said print(string.match("DoTehAlan", "UHGYTFR")) it would print nil
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Apr 2016 12:09 PM
local debounce = false

findPlayer = function(name)
if game.Players:FindFirstChild(name) then
return game.Players[name]
end
end

script.Parent.MouseButton1Click:connect(function()
if not debounce then
debounce = true
local plr = findPlayer(script.Parent.Parent.CNameTextBox.Text)
if plr then
print(plr.Name)
end
wait(5)
debounce = false
end
end)


Report Abuse
JayTheDJ is not online. JayTheDJ
Joined: 07 Aug 2011
Total Posts: 262
12 Apr 2016 12:16 PM
Figured it out.

searchTerm = "JayTheDJ"

for index, child in pairs (game.Players:GetChildren()) do
wait()
if string.match(child.Name, searchTerm .. "%w*") then
print('found it')
end
end

I'll just replace the searchTerm's value with the TextBox.Text and it'll work beautifully.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Apr 2016 12:17 PM
Thats a pretty ugly way to do it but okay.


Report Abuse
JayTheDJ is not online. JayTheDJ
Joined: 07 Aug 2011
Total Posts: 262
12 Apr 2016 12:18 PM
@TimeTicks

I would need it to account for partial names as well.
Report Abuse
DoTehAlan is not online. DoTehAlan
Joined: 13 Feb 2011
Total Posts: 626
12 Apr 2016 12:24 PM
Basically what I put but ok
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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