Hi I want this script to invisible people when you sit in a seat. And when you not touch it uninvisibles you. Script:
script.Parent.Touched:Connect(function(plr) if plr.Parent:FindFirstChild("Humanoid") then for i, v in pairs(plr.Parent:GetChildren()) do if v:IsA("BasePart") then v.Transparency = 1 end if v:IsA("Accessory") then v.Handle.Transparency = 1 for index, value in pairs(v.Handle:GetDescendants()) do if value:IsA("ParticleEmitter") then value.Transparency = NumberSequence.new(1) end end end end plr.Parent.Head.face.Transparency = 1 end end) script.Parent.TouchEnded:Connect(function(plr) if plr.Parent:FindFirstChild("Humanoid") then for i, v in pairs(plr.Parent:GetChildren()) do if v:IsA("BasePart") then v.Transparency = 0 end if v:IsA("Accessory") then v.Handle.Transparency = 0 for index, value in pairs(v.Handle:GetDescendants()) do if value:IsA("ParticleEmitter") then value.Transparency = NumberSequence.new(0) end end end end plr.Parent.Head.face.Transparency = 0 plr.Parent.HumanoidRootPart.Transparency = 1 end end)
What I have tried is changing basepart to Seat but it didn't work :(
You can use a seat's Occupant
property and the GetPropertyChangedSignal
signal to detect when a player starts to sit in a seat:
local seat = script.Parent local PreviousHumanoid = nil local function Sat() local Humanoid = seat.Occupant if (Humanoid ~= nil) then -- player entered seat PreviousHumanoid = Humanoid for i, v in pairs(Humanoid.Parent:GetChildren()) do if v:IsA("BasePart") then v.Transparency = 1 end if v:IsA("Accessory") then v.Handle.Transparency = 1 for index, value in pairs(v.Handle:GetDescendants()) do if value:IsA("ParticleEmitter") then value.Transparency = NumberSequence.new(1) end end end end Humanoid.Parent.Head.face.Transparency = 1 else -- player left seat if (PreviousHumanoid.Parent == nil) then return -- check if the humanoid still exists (check if player left) end Humanoid = PreviousHumanoid for i, v in pairs(Humanoid.Parent:GetChildren()) do if v:IsA("BasePart") then v.Transparency = 0 end if v:IsA("Accessory") then v.Handle.Transparency = 0 for index, value in pairs(v.Handle:GetDescendants()) do if value:IsA("ParticleEmitter") then value.Transparency = NumberSequence.new(0) end end end end Humanoid.Parent.Head.face.Transparency = 0 Humanoid.Parent.HumanoidRootPart.Transparency = 1 end end seat:GetPropertyChangedSignal('Occupant'):Connect(Sat)