Attempt to connect failed/ attempt to call a nil value?
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.