|
| 20 Jun 2015 04:37 AM |
I'm trying to see if the player has a shirt/pants and if they don't the value is 0. What's wrong with this?
local tshirtId = chr:FindFirstChild("Shirt").ShirtTemplate:match("%d+") or 0 local pantsId = chr:FindFirstChild("Pants").PantsTemplate:match("%d+") or 0 |
|
|
| Report Abuse |
|
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
|
| 20 Jun 2015 04:42 AM |
| There's nothing wrong with the code, what's your error? |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 04:43 AM |
04:42:07.942 - Auto-Saving... 04:42:47.389 - Auto-Saving... 04:42:49.241 - Players.Player.PlayerGui.GUI.UniformsGUI.Uniform4.Uniform4.:5: attempt to index a nil value 04:42:49.241 - Stack Begin 04:42:49.242 - Script 'Players.Player.PlayerGui.GUI.UniformsGUI.Uniform4.Uniform4.', Line 5 04:42:49.242 - Stack End |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 04:43 AM |
line 5 is tshirtId
i dont get it lol |
|
|
| Report Abuse |
|
|
DrSaint
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 18429 |
|
| |
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
| |
|
|
| 20 Jun 2015 04:44 AM |
local plr = game.Players.LocalPlayer local chr = plr.Character or plr.CharacterAdded:wait() local btn = plr.PlayerGui.GUI:WaitForChild("UniformsGUI"):WaitForChild("Uniform4") btn.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?username="..plr.Name local tshirtId = chr:FindFirstChild("Shirt").ShirtTemplate:match("%d+") or 0 local pantsId = chr:FindFirstChild("Pants").PantsTemplate:match("%d+") or 0
btn.MouseButton1Down:connect(function() print(tshirtId, pantsId) end)
LocalScript by the way. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 04:45 AM |
it doesn't say anything about line 4
that's line 5 :P |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 04:47 AM |
| By the way, if a player doesn't have Shirt or Pants equipped from the website before they spawn they don't have Shirt or Pants. That's why I wanted to :FindFirstChild and then if it's nil (or false) it'd turn to 0. |
|
|
| Report Abuse |
|
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
|
| 20 Jun 2015 04:48 AM |
| You might need a :WaitForChild() for GUI |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 04:49 AM |
| Nah, that works. I've tested that online and in play solo. It works. It just won't turn to zero! |
|
|
| Report Abuse |
|
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
|
| 20 Jun 2015 04:50 AM |
| Do a if statement to see if chr:FindFirstChild("Shirt") and Pants. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 04:53 AM |
| I was hoping I could do it in one variable declaration. |
|
|
| Report Abuse |
|
|
| |
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
| |
|
|
| 20 Jun 2015 05:09 AM |
| trying not to use if statements... do i have to? |
|
|
| Report Abuse |
|
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
|
| 20 Jun 2015 05:13 AM |
| Try it and see if it works. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 05:15 AM |
--Idk string patern but try it.
local player = game:FindService("Players").LocalPlayer; player.Character:WaitForChild("Humanoid");
player:WaitForChild("PlayerGui"); player.PlayerGui:WaitForChild("UniForm4");
player.PlayerGui:FindFirstChild("UniForm4").Image = "http://www.roblox.com/Thumbs/Avatar.ashx?username="..player.Name;
if player.Character:FindFirstChild("Shirt") then --ur shirt code end;
if player.Character:FindFirstChild("Pants") then
end;
|
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 05:17 AM |
| you just nuked my code lol |
|
|
| Report Abuse |
|
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
|
| 20 Jun 2015 05:18 AM |
| @AbstractMadness who? Your string pattern is fine. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 05:19 AM |
| in case you define something worng + i dont trust player.CharacterAdded:wait() -- no wait !! |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 05:19 AM |
captain xd and it didn't work.
local plr = game.Players.LocalPlayer local chr = plr.Character or plr.CharacterAdded:wait() local btn = plr.PlayerGui.GUI:WaitForChild("UniformsGUI"):WaitForChild("Uniform4") btn.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?username="..plr.Name local tshirtId = 0 local pantsId = 0 wait()
if chr:FindFirstChild("Shirt") then tshirtId = chr:FindFirstChild("Shirt").ShirtTemplate:match("%d+") end
if chr:FindFirstChild("Pants") then pantsId = chr:FindFirstChild("Pants").PantsTemplate:match("%d+") end
btn.MouseButton1Down:connect(function() print(tshirtId.." | "..pantsId) end)
prints 0 | 0 even though i have clothes on. |
|
|
| Report Abuse |
|
|
StarWars
|
  |
| Joined: 04 Jan 2007 |
| Total Posts: 500 |
|
|
| 20 Jun 2015 05:29 AM |
I managed to get it working with this
local plr = game.Players.LocalPlayer local chr = plr.Character or plr.CharacterAdded:wait() local btn = plr.PlayerGui.GUI:WaitForChild("UniformsGUI"):WaitForChild("Uniform4") btn.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?username="..plr.Name
wait(0.5)
local tshirtId = chr:FindFirstChild("Shirt").ShirtTemplate:match("%d+") or 0 local pantsId = chr:FindFirstChild("Pants").PantsTemplate:match("%d+") or 0
btn.MouseButton1Down:connect(function() print(tshirtId.." | "..pantsId) end)
looks like the character is spawning too fast for it to find the Shirt or Pants.
You can add the wait() or have it check when you press the button |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 05:29 AM |
I. HATe. LoCAl. SCripTS.
thank you m8. |
|
|
| Report Abuse |
|
|
| |
|