Write a Roblox script that would make you see other players through walls when you have…
- User
Write a Roblox script that would make you see other players through walls when you have picked an item called "Super Vision" for 5 minutes
- Assistant
Write a Roblox script that would make you see other players through walls when you have picked an item called "Super Vision" for 5 minutes
Certainly! Below is a comprehensive guide along with a Roblox Lua script that enables a player to see other players through walls for 5 minutes after picking up an item called "Super Vision." This effect is achieved by using the Highlight object, which allows characters to be visible through obstacles.
ReplicatedStorage.Highlight object to make other players' characters visible through walls.First, ensure that the "Super Vision" tool exists in your game. Here's how to create it:
ReplicatedStorage and select Insert Object > Tool."Super Vision".Note: The Tool should have a Handle part for it to be usable.
Next, create a LocalScript that will handle the activation of the Super Vision effect.
StarterPlayer > StarterPlayerScripts.StarterPlayerScripts and select Insert Object > LocalScript."SuperVisionScript".Insert the following script into SuperVisionScript:
-- LocalScript: StarterPlayerScripts/SuperVisionScript
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
-- Constants
local SUPERVISION_DURATION = 300 -- Duration in seconds (5 minutes)
-- Player and Character References
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")
-- References to Super Vision Tool
local superVisionTool = ReplicatedStorage:WaitForChild("Super Vision", 10)
if not superVisionTool then
warn("Super Vision Tool not found in ReplicatedStorage.")
return
end
-- Function to add Highlight to a character
local function addHighlight(otherCharacter)
if not otherCharacter or not otherCharacter:FindFirstChild("HumanoidRootPart") then return end
-- Avoid adding multiple Highlights
if otherCharacter:FindFirstChild("SuperVisionHighlight") then return end
local highlight = Instance.new("Highlight")
highlight.Name = "SuperVisionHighlight"
highlight.FillColor = Color3.fromRGB(0, 255, 0) -- Green fill
highlight.OutlineColor = Color3.fromRGB(255, 255, 255) -- White outline
highlight.FillTransparency = 0.5 -- 50% transparent fill
highlight.OutlineTransparency = 0 -- No transparency for outline
highlight.Adornee = otherCharacter
highlight.Parent = otherCharacter
end
-- Function to remove Highlight from a character
local function removeHighlight(otherCharacter)
if not otherCharacter then return end
local highlight = otherCharacter:FindFirstChild("SuperVisionHighlight")
if highlight then
highlight:Destroy()
end
end
-- Function to apply Highlight to all current players
local function applySuperVision()
for _, otherPlayer in ipairs(Players:GetPlayers()) do
if otherPlayer ~= player and otherPlayer.Character then
addHighlight(otherPlayer.Character)
end
end
-- Listen for new players joining while Super Vision is active
Players.PlayerAdded:Connect(function(newPlayer)
newPlayer.CharacterAdded:Connect(function(newCharacter)
addHighlight(newCharacter)
end)
if newPlayer.Character then
addHighlight(newPlayer.Character)
end
end)
-- Listen for characters respawning
Players.PlayerRemoving:Connect(function(leavingPlayer)
if leavingPlayer ~= player and leavingPlayer.Character then
removeHighlight(leavingPlayer.Character)
end
end)
end
-- Function to remove all Highlights
local function removeAllHighlights()
for _, otherPlayer in ipairs(Players:GetPlayers()) do
if otherPlayer ~= player and otherPlayer.Character then
removeHighlight(otherPlayer.Character)
end
end
end
-- Function to activate Super Vision
local function activateSuperVision()
applySuperVision()
-- Timer to remove effect after duration
delay(SUPERVISION_DURATION, function()
removeAllHighlights()
end)
end
-- Function to handle tool equipped
local function onToolEquipped()
activateSuperVision()
-- Optionally, remove the tool after activation
-- script.Parent:Destroy()
end
-- Clone the Super Vision tool into the player's backpack
local userTool = superVisionTool:Clone()
userTool.Parent = backpack
-- Connect the Equipped event to activate Super Vision
userTool.Equipped:Connect(onToolEquipped)
-- Optional: Handle tool being added to backpack after initial setup
backpack.ChildAdded:Connect(function(child)
if child.Name == "Super Vision" and child:IsA("Tool") then
child.Equipped:Connect(onToolEquipped)
end
end)
The script above sets the Highlight to have a green fill with a white outline. You can customize these settings to fit your game's aesthetic:
Color3.fromRGB(0, 255, 0) to any color you prefer.Color3.fromRGB(255, 255, 255) to any color you prefer.0.5 to make the fill more or less transparent.0 if you want the outline to be transparent.Example:
highlight.FillColor = Color3.fromRGB(255, 0, 0) -- Red fill
highlight.OutlineColor = Color3.fromRGB(0, 0, 0) -- Black outline
highlight.FillTransparency = 0.3 -- 30% transparent fill
highlight.OutlineTransparency = 0.1 -- 10% transparent outline
F5 key).Backpack.Highlight settings.Note: For testing purposes, you might want to reduce the SUPERVISION_DURATION to a shorter time, like 30 seconds.
Services and References: The script starts by referencing essential services like Players and ReplicatedStorage. It also grabs the local player and their character.
Highlight Functions:
addHighlight: Adds a Highlight object to another player's character to make them visible through walls.removeHighlight: Removes the Highlight object from a character.Applying Super Vision:
applySuperVision: Iterates through all current players and applies the highlight to their characters. It also sets up listeners for new players joining and characters respawning.removeAllHighlights: Removes highlights from all players.Activating Super Vision:
activateSuperVision: Applies the highlights and sets a timer (delay) to remove them after the specified duration (SUPERVISION_DURATION).Handling the Tool:
ReplicatedStorage into the player's Backpack.Equipped event of the tool to activate Super Vision when the tool is equipped.Client-Side Effect: Since the script uses a LocalScript and Highlight, the effect is only visible to the player who activated it.
Performance: Applying many Highlight objects can affect performance. Ensure to test in scenarios with multiple players.
Security: This method ensures that only the player who picked up the "Super Vision" can see others through walls. Other players won't experience any changes.
Cleanup: The script ensures that highlights are removed after the duration. However, it's good practice to handle cases where the player leaves the game or the character respawns prematurely.
By following the steps above, you'll enable players to have enhanced vision in your Roblox game, allowing them to see others through walls for a limited time. This can be a fun power-up or ability in various game genres, such as stealth, battle, or exploration games.
Feel free to adjust the script to better fit the mechanics and aesthetics of your specific game!
Not yet included in a published release.