Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to connect failed/ attempt to call a nil value?

Asked by 7 years ago

I have a barricade with an invisible part in front of hit. If the barricade is damaged, then this script is inserted into the part so that a player can fix the barricade. At first, the script runs fine and I get the RepairGui when I touch the part, but things go south when an npc(zombie) goes through the barricade and touches the part. The script out put says, "Attempt to connect failed: Passed value is not a function" and then proceeds to spam, "attempt to call a nil value" as more zombies walk through it. What's wrong?

function onTouched(hit) local PlayerTouching = game.Players:GetPlayerFromCharacter(hit.Parent) if PlayerTouching ~= nil then if PlayerTouching.PlayerGui.RepairGui.Enabled == false then PlayerTouching.PlayerGui.RepairGui.Enabled = true local Repairing = game.Lighting.Repairing:Clone() Repairing.Parent = PlayerTouching.Character end end end function unTouched(hit) local PlayerTouching = game.Players:GetPlayerFromCharacter(hit.Parent) if PlayerTouching ~= nil then PlayerTouching.PlayerGui.ReviveGui.Enabled = false if PlayerTouching.Character:FindFirstChild("Repairing") ~= nil then PlayerTouching.Character.Repairing:Remove() end end end script.Parent.Touched:connect(onTouched) script.Parent.TouchEnded:connect(unTouched)

Any help is appreciated.

1 answer

Log in to vote
0
Answered by 7 years ago

What line is the error in? and please change the code you put in your question with the properly indented one I am giving. (Please note the code I provided is just your code easier to read. Dont expect it to work if your's doesn't. You may try if you want though.)

function onTouched(hit)
  local PlayerTouching = game.Players:GetPlayerFromCharacter(hit.Parent)
  if PlayerTouching ~= nil then
    if PlayerTouching.PlayerGui.RepairGui.Enabled == false then 
      PlayerTouching.PlayerGui.RepairGui.Enabled = true
      local Repairing = game.Lighting.Repairing:Clone()
      Repairing.Parent = PlayerTouching.Character
    end
  end
end

function unTouched(hit)
  local PlayerTouching = game.Players:GetPlayerFromCharacter(hit.Parent)
  if PlayerTouching ~= nil then
    PlayerTouching.PlayerGui.ReviveGui.Enabled = false
    if PlayerTouching.Character:FindFirstChild("Repairing") ~= nil then 
      PlayerTouching.Character.Repairing:Remove()
    end
  end
end 

script.Parent.Touched:connect(onTouched)
script.Parent.TouchEnded:connect(unTouched)
0
Sorry, I forgot to format it correctly. The errors don't give me a line sadly, i'll show you exactly what they say. FrogNinjaX 222 — 7y
0
11:47:25.454 - Attempt to connect failed: Passed value is not a function / 11:47:26.276 - attempt to call a nil value FrogNinjaX 222 — 7y
Ad

Answer this question