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 |
|
|
|
| 12 Apr 2016 12:00 PM |
In LocalScripts, you can define the player like so:
local Player = game.Players.LocalPlayer |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 13 Feb 2011 |
| Total Posts: 626 |
|
|
| 12 Apr 2016 12:24 PM |
| Basically what I put but ok |
|
|
| Report Abuse |
|
|