Ok, well first of all, you haven't checked to see if humanoid is actually existent nor whether the player exists. Also, in the for loop you haven't checked to see if p is a part. These could all lead to problems, for example if any part touched that, the script would be broken for the duration of the time that server's up, simply because the script returned an error because it was told that the part had a humanoid with it didn't! Here's the fixed code:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil and game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
if hit.Parent.Humanoid.Sit == true then
for i, p in pairs(hit.Parent:GetChildren()) do
if p:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
p.Transparency = 1
end
end
end
if hit.Parent.Humanoid.Sit == false then
for i, p in pairs(hit.Parent:GetChildren()) do
if p:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
p.Transparency = 0
end
end
end
end
end)
If this works for you or helps you to understand please vote up and accept this as your answer.
2 comments
Did you try using a While loop that detects if the player is Sitting? Break the loop once he gets up and set the Transparency back after the loop
nope