ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 02:02 PM |
| So I am looking to make a GUI and script that displays which weapon is equipped, so then how would I look to access the weapon, for example, find out which weapon the player has equipped. |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 02 Feb 2016 02:22 PM |
Just some pseudo code. If that's the right word :p
local function GetWeaponEquipped() for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do if v:IsA("Tool") then return v.Name end end end
print(GetWeaponEquipped())
This would either print nil, if there is no weapon equipped, or it would print the name of the tool that was equipped. |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 02:24 PM |
| Thanks that's very helpful :) |
|
|
| Report Abuse |
|
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 02:37 PM |
local function GetWeaponEquipped() for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do if v:isA("Tool") then return v.Name end end end
WepName = script.Parent.Frame.Text.Equipped
WepName.Text = v.Name
So this is why I briefly came up with, however it does not work, how can I make this work? |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
|
| 02 Feb 2016 02:41 PM |
| WelpName.Text = GetWeaponEquipped() |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 02:42 PM |
Made some changes however the script is still not working :/ here are the changes
local function GetWeaponEquipped() for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do if v:isA("Tool") then return v.Name end
local WepName = script.Parent.Frame.Text.Equipped
WepName.Text = v.Name
end end
|
|
|
| Report Abuse |
|
|
|
| 02 Feb 2016 02:42 PM |
| Did you use a localScript? |
|
|
| Report Abuse |
|
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 02 Feb 2016 02:43 PM |
local function GetWeaponEquipped() for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do if v:isA("Tool") then return v.Name end end end
local WepName = script.Parent.Frame.Text.Equipped
WepName.Text = GetWeaponEquipped() |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 02:50 PM |
| bump. It still seems to not be working :/ |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
|
| 02 Feb 2016 02:53 PM |
| put that into a localscript |
|
|
| Report Abuse |
|
|
Exterity
|
  |
| Joined: 19 Dec 2009 |
| Total Posts: 4504 |
|
|
| 02 Feb 2016 02:54 PM |
| how did you learn to script lua |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 02:55 PM |
| I already put it into a local script but it still was not working. |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
xlaser23
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 20341 |
|
|
| 02 Feb 2016 03:05 PM |
errors?
http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$329 Tx504 (づ ゚ ³ ゚)づ |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 03:07 PM |
I dun goofed and entirely forgot to check error messages, but this is what I got "Players.Player1.PlayerGui.Weapon Display.LocalScript:11: bad argument #3 to 'Text' (string expected, got nil)" |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 02 Feb 2016 03:12 PM |
| Still it is not working :/ |
|
|
| Report Abuse |
|
|
|
| 02 Feb 2016 03:13 PM |
| WelpName = tostring(GetWeaponEquipped()) |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|