Hi,
So i have a script that should check who touched part last time and if this was “Villager” (its npc name) then it will make a bool values value true, but for some reason this script don’t count npc. For example i will check if thing that last time touched part was named “HumanoidRootPart” and if npc goes away then value do not changing but if i will touch part and go away script will change. I don’t know why but this script don’t see npc. npc is not local so i don’t know.
script.Parent.TouchEnded:Connect(function(hit)
if hit.Name == "Villager" then
script.Parent.BoolValue.Value = true
end
end)
your code will work if you used a Touched Event then you can just do a touch ended if you use A touch ended event
a sample code
local part = script.Parent
local function onPartTouchEnded(otherPart)
print(part.Name .. " is no longer touching " .. otherPart.Name)
end
part.TouchEnded:Connect(onPartTouchEnded)
try converting your code to this
local parent = script.Parent
local function Functions(otherPart) -- why do we check if there is a humanoid because it might not be a fake player it might be a object
if otherPart:FindFirstChild("Humanoid") and otherPart.Name == "Villager" then
script.Parent.BoolValue.Value = true
end
end
parent.TouchEnded:Connect(Functions)
PS: Your code will only work if the bool value is false