Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Im trying to make a invisable script which I made and I am kinda confused on what I did?

I'm trying to make a invisible script so whenever I press M I will be able to stay invisible for 9999 seconds or mostly forever I tried to use one of my old script to do it and still never worked out. Please help me fix this.

Invisible script

local settings = { --This is a table, this table will store all the variables that you can change.
damageTime = 1, -- How many times It will damage the player
inbetweenTime = .1, -- The time you have to wait until It damages again
damage = 0, -- How much damage it will do
Transparency = false,
Transparency = false,
timeUntilUse = 15, -- Change this to the time you want it to wait until you can punch again
}


    repeat wait() until game.Players.LocalPlayer.Character
function onKeyPress(inputObject,gameProcessedEvent)
    settings.Transparency = false
    if inputObject.KeyCode == Enum.KeyCode.M and not settings.Transparency then
    settings.Transparency = true
game.Players.LocalPlayer.Character.HumanoidRootPart.Touched:Connect(function(hit) --[[ This is a function which will fire when it is touched, make sure to put the player you want in the brackets w/ .HumanoidRootPart  --]]
if inputObject.KeyCode == Enum.KeyCode.M and settings.Transparency == true then --[[ This will check if it hits something w/ a humanoid --]]
for i = 1,settings.damageTime do
    if not settings.Transparency then
        settings.Transparency = true
    wait(settings.inbetweenTime) -- this will wait for the time classified in settings.
    settings.Transparency = 2
    end
end
wait(settings.timeUntilUse)
settings.Transparency = 2
end
end)
end
    end

game:GetService('UserInputService').InputBegan:Connect(onKeyPress)

1 comment

0

Lol its kinda crazy Atm

1 answer

I'm just gonna go based on what you asked, and not from the comments in the script because it's a little confusing lol. This can easily be done with UserInputService and a for loop.

This script will allow for you to press M once to become invisible, and press it again to become visible. After 3 seconds, of course, to prevent spam. You can change how long the debounce lasts.

local UserInputService = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character and plr.Character:FindFirstChild('HumanoidRootPart')
local char = plr.Character
local Debounce = false --To prevent from happening too many times.
local Enabled = false --So it can be used again

UserInputService.InputBegan:Connect(function(Input,GPE)
	if Input.KeyCode == Enum.KeyCode.M then
		if Enabled == false and Debounce == false then
			Debounce = true
			for i,v in pairs(plr.Character:GetChildren()) do
				if v:IsA('BasePart') and not v.Name == 'HumanoidRootPart' then
					v.Transparency = 1
				end
			end
			wait(3) --Debounce wait time
			Debounce = false
		elseif Enabled == true and Debounce == false then
			Debounce = true
			for i,v in pairs(plr.Character:GetChildren()) do
				if v:IsA('BasePart') and not v.Name == 'HumanoidRootPart' then
					v.Transparency = 0
				end
			end
			wait(3) --Debounce wait time
			Debounce = false
		end
	end
end)

1 comment

0

where can i put the script? i put it on a local script inside starterplayerscripts.

This discussion is preserved as it was. New answers, comments, and votes are closed.