|
| 18 Jul 2017 11:12 PM |
I'm looking to make a way for janitors in my game to check the PH level of a pool (I'm new to scripting) and first off: would I use a NumberValue for it?
This is the little script I have: brick = script.Parent guiText = game.StarterGui.ScreenGui.Frame.TextBox.Text brick.Touched:connect(function(part) if script.Parent.Parent.Parent.TeamColor == BrickColor.new("White") then guiText = script.Parent.PHLevel end end) |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 18 Jul 2017 11:53 PM |
| Replace "script.Parent ... .Parent" with variables, so that it's easier to read the script, not to mention the tiny performance gain. |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 18 Jul 2017 11:54 PM |
| Have you tried? Is there a problem? |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2017 06:56 PM |
Yes it gives an error saying: Touched is not a valid member of Workspace.
|
|
|
| Report Abuse |
|
|
Mr_Crunch
|
  |
| Joined: 16 Jul 2016 |
| Total Posts: 275 |
|
|
| 19 Jul 2017 07:00 PM |
| make sure your script is within the actual brick they're touching. |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2017 07:00 PM |
Fixed that now says:
16:59:49.422 - Workspace.PoolWater.Script:3: attempt to index global 'hit' (a nil value) |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 19 Jul 2017 07:04 PM |
??
Did you copy a different script? Because you might've changed the parameter name...
And why are you changing the gui from StarterGui? If you want it to change the player's GUI you have to use PlayerGui. |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2017 07:45 PM |
You shouldn't be using this
if script.Parent.Parent.Parent.TeamColor == BrickColor.new('White') then
Also, where is your script located
Thanks! AyeeAndrxw |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2017 08:05 PM |
brick = script.Parent localTeam = game.Players.LocalPlayer.Team phLevel = script.Parent.PHLevel.Value function onClicked(playerWhoClicked) if localTeam == "Janitors" then print("7") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
heres my new script no errors, just does nothing |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 19 Jul 2017 08:09 PM |
Make sure it's a script and put this:
brick = script.Parent phLevel = script.Parent.PHLevel.Value function onClicked(playerWhoClicked) if playerWhoClicked.Team == "Janitors" then print("7") end end
script.Parent.ClickDetector.MouseClick:connect(onClicked) |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2017 08:12 PM |
| Tried that, still doesn't print |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 19 Jul 2017 08:14 PM |
brick = script.Parent phLevel = script.Parent.PHLevel.Value function onClicked(playerWhoClicked) if playerWhoClicked.Team == game:GetService("Teams").Janitors then print("7") else print(playerWhoClicked.Team) end end
script.Parent.ClickDetector.MouseClick:connect(onClicked) |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2017 08:16 PM |
Okay make sure that it is a proper script and it is inside of the brick
local Part = script.Parent local PHLevel = Part.PHLevel
Part.ClickDetector.MouseButton1Click:Connect(function(player) if player then local team = Player.Team if team == 'Janitors' then print(7) end)
Thanks! AyeeAndrxw |
|
|
| Report Abuse |
|
|
| |
|
pidgey
|
  |
| Joined: 16 Jan 2008 |
| Total Posts: 2739 |
|
|
| 19 Jul 2017 08:16 PM |
you cant compare an object with a string value, Player.Team == "Janitors" will always be false. theres a property in Team called Name, compare Team.Name with "Janitors" instead
if playerWhoClicked.Team.Name == "Janitors" then
or if playerWhoClicked.Team == game.Teams.Janitors |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2017 08:19 PM |
You get the idea of what I was doing. Wasn't using studio to do this
Thanks! AyeeAndrxw |
|
|
| Report Abuse |
|
|