Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Shared ModuleScript (in ReplicatedStorage under Folder "shared")
- return function(Player, Transparency)
- -- Get Character and Appropriate Transparency value if not already passed TransparencyVal = (1+1)%2 == 0 or (0+1)%2 == 1
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local TransparencyVal = Transparency or (Character:WaitForChild("Head").Transparency+1)%2
- for _, Part in pairs(Character:GetChildren()) do
- -- Srt Transparency of parts according to TransparencyVal
- if (Part:IsA("Part") or Part:IsA("MeshPart")) and Part.Name ~= "HumanoidRootPart" then
- Part.Transparency = TransparencyVal
- if Part.Name == "Head" then
- -- Edge case; if not modified you would be able to see the face
- Part:FindFirstChild("face").Transparency = TransparencyVal
- end
- elseif Part:IsA("Accessory") then
- -- Accessories have part handles that can be manipulated like a part
- Part.Handle.Transparency = TransparencyVal
- end
- end
- end
- ------------------------------------------------------------------------------------------------------------------------------
- -- LocalScript (In StarterPlayerScripts)
- local ReplicatedStorage, ContextActionService, Players = game:GetService("ReplicatedStorage"), game:GetService("ContextActionService"), game:GetService("Players")
- local Remotes, SharedModules = ReplicatedStorage:WaitForChild("Remotes"), ReplicatedStorage:WaitForChild("shared")
- local Player = Players.LocalPlayer
- local Transparency = -0.7
- local function SendReqForInvisibility(ActionName, Input)
- -- The Bind function may be called to make the player visible or invisible
- if ActionName == "Invisibility" and Input == Enum.UserInputState.Begin then
- -- We invoke server to make sure the server makes the player invisible to everybody else
- -- If we did not do this, the server would take longer than the client to make itself invisible, and the client would be invisible even to itself
- Remotes.MakeInvisible:InvokeServer()
- -- Asjust transparency
- Transparency = -Transparency
- -- Same action as server, but we pass a transparency value as an argument
- require(SharedModules.Invisibility)(Player, Transparency)
- end
- end
- -- Binds Keycode E to function "SendReqForInvisibility"
- ContextActionService:BindAction("Invisibility", SendReqForInvisibility, false, Enum.KeyCode.E)
- ------------------------------------------------------------------------------------------------------------------------------
- -- ServerScript (in ServerScriptService)
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Remotes, SharedModules = ReplicatedStorage:WaitForChild("Remotes"), ReplicatedStorage:WaitForChild("shared")
- local function MakeInvisible(Player)
- -- Calls the function inside Shared ModuleScript, no transparency value is passed so the module will determine the appropriate value on its own
- return require(SharedModules.Invisibility)(Player)
- end
- Remotes.MakeInvisible.OnServerInvoke = MakeInvisible
Advertisement
Advertisement