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
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to do this or 0?

Previous Thread :: Next Thread 
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
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 is not online. 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
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
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
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
20 Jun 2015 04:43 AM
line 5 is tshirtId

i dont get it lol
Report Abuse
DrSaint is not online. DrSaint
Joined: 14 Oct 2009
Total Posts: 18429
20 Jun 2015 04:44 AM
Full script plz
Report Abuse
StarWars is not online. StarWars
Joined: 04 Jan 2007
Total Posts: 500
20 Jun 2015 04:44 AM
Is line 4 declaring chr?
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
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
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
20 Jun 2015 04:45 AM
it doesn't say anything about line 4

that's line 5 :P
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
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 is not online. StarWars
Joined: 04 Jan 2007
Total Posts: 500
20 Jun 2015 04:48 AM
You might need a :WaitForChild() for GUI
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
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 is not online. 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
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
20 Jun 2015 04:53 AM
I was hoping I could do it in one variable declaration.
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
20 Jun 2015 05:06 AM
h3lp
Report Abuse
StarWars is not online. StarWars
Joined: 04 Jan 2007
Total Posts: 500
20 Jun 2015 05:07 AM
That didn't work?
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
20 Jun 2015 05:09 AM
trying not to use if statements... do i have to?
Report Abuse
StarWars is not online. StarWars
Joined: 04 Jan 2007
Total Posts: 500
20 Jun 2015 05:13 AM
Try it and see if it works.
Report Abuse
CaptainSource is not online. CaptainSource
Joined: 08 Jun 2013
Total Posts: 848
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
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
20 Jun 2015 05:17 AM
you just nuked my code lol
Report Abuse
StarWars is not online. StarWars
Joined: 04 Jan 2007
Total Posts: 500
20 Jun 2015 05:18 AM
@AbstractMadness who? Your string pattern is fine.
Report Abuse
CaptainSource is not online. CaptainSource
Joined: 08 Jun 2013
Total Posts: 848
20 Jun 2015 05:19 AM
in case you define something worng + i dont trust player.CharacterAdded:wait() -- no wait !!
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
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 is not online. 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
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
20 Jun 2015 05:29 AM
I. HATe. LoCAl. SCripTS.

thank you m8.
Report Abuse
CaptainSource is not online. CaptainSource
Joined: 08 Jun 2013
Total Posts: 848
20 Jun 2015 05:29 AM
ohh i got ur script brb*
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