01 | part = script.Parent |
02 |
03 | part.Touched:Connect( function (hit) |
04 | if hit.Name = = "NodeOrb" and script.Parent.Parent.Parent.Parent.Character.TeamCol.Value = = "Tred" then |
05 | hit.CaptureStatus.Value = hit.CaptureStatus.Value + 1 |
06 | end |
07 | if hit.Name = = "NodeOrb" and script.Parent.Parent.Parent.Parent.Character.TeamCol.Value = = "Tblue" then |
08 | hit.CaptureStatus.Value = hit.CaptureStatus.Value - 1 |
09 | end |
10 | end ) |
the script is in a part which is inside a tool, and Im trying to access a stringvalue inside the tool owners character but Im having trouble getting to it, I thought what I had would work but I keep getting an error were the script is trying to get to the stringvalue.
is there something Im doing wrong?
.Character
Here is a example:
01 | local tool = script.Parent |
02 |
03 | tool.Equiped:Connect( function () |
04 | print ( "Player name: " .. script.Parent.Parent.Name) |
05 | --[[ |
06 | script = Script |
07 | script.Parent = tool |
08 | script.Parent.Parent = character. |
09 | ]] |
10 | end ) |
Here is fixed script:
01 | local tool = script.Parent.Parent -- Added variable for tool |
02 | local part = script.Parent -- Use local Variable = ... not Variable = ... |
03 |
04 | part.Touched:Connect( function (hit) |
05 | if tool.Parent:FindFirstChild( "Humanoid" ) then -- Check if is in char. |
06 | if hit.Name = = "NodeOrb" and tool.Parent.TeamCol.Value = = "Tred" then |
07 | hit.CaptureStatus.Value = hit.CaptureStatus.Value + 1 |
08 | end |
09 | if hit.Name = = "NodeOrb" and tool.Parent.TeamCol.Value = = "Tblue" then |
10 | hit.CaptureStatus.Value = hit.CaptureStatus.Value - 1 |
11 | end |
12 | end |
13 | end ) |