Someone please help

I want to make it so that when you press E, the indicators go off, but I don’t know how to make it stop after you press it again.

local seat = script.Parent
local UserInputService = game:GetService("UserInputService")

seat.ChildAdded:Connect(function(child)
	if child.Name == "SeatWeld" then
		local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
		if player ~= nil then

		end
	end
end)

local function onInputBegan(input, _gameProcessed)
	if input.KeyCode == Enum.KeyCode.E then
		script.Parent.Parent.Right.Material = ("Neon")
		wait(0.5)
		script.Parent.Parent.Right.Material = ("SmoothPlastic")
		wait(0.5)
	end
end
UserInputService.InputBegan:Connect(onInputBegan)

seat.ChildRemoved:Connect(function(child)
	if child.Name == "SeatWeld" then
		local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
		if player ~= nil then

		end
	end
end)

what indicators? do you have a video of what it is doing right now? could you explain further

The script turns the Right material from Neon to Plastic. It does it once. How can I make it repeat until E is pressed again?

so what im getting, you want the right part’s material to switch between neon and plastic until they press e again

just add two variables, one called looping two called pressedE or pressed or anything that makes sense for you

local looping = false
local pressed = false

-- this goes inside the E press function
if not looping then
    looping = true
    while not pressed do
        change material
        task.wait(0.5)
        change material
    end
    looping = false
    pressed = false
else
    pressed = true
end

you could simply this to just this

local looping = false

-- this goes inside the E press function
if not looping then
    looping = true
    while looping do
        change material
        task.wait(0.5)
        change material
    end
else
    looping = false
end

tweens could also work using the constant easing style (not 100% sure this will work, i cant test it at this time)

local TweenService = game:GetService("TweenService")
local pressed = false

-- goes inside E press function 
if not pressed then
    local function CreateTween(material)
        local t = TweenService:Create(part, TweenInfo.new(0.01, EasingStyle.Constant), { Material = material }
        t.Completed:Wait()
        if pressed then return end
        CreateTween((material == Enum.Material.Neon and Enum.Material.Plastic or Enum.Material.Neon))
    end
    CreateTween(Enum.Material.Neon)
else
    pressed = true
end
local seat = script.Parent
local UserInputService = game:GetService("UserInputService")

local offOrOn = "Off"

seat.ChildAdded:Connect(function(child)
	if child.Name == "SeatWeld" then
		local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
		if player ~= nil then

		end
	end
end)

local function onInputBegan(input, _gameProcessed)
	if input.KeyCode == Enum.KeyCode.E then
if offOrOn == "Off" then
offOrOn = "On"
repeat
		script.Parent.Parent.Right.Material = ("Neon")
		wait(0.5)
		script.Parent.Parent.Right.Material = ("SmoothPlastic")
		wait(0.5)
until offOrOn == "Off"
elseif offOrOn  == "On" then

offOrOn = "Off"
end
	end
end
UserInputService.InputBegan:Connect(onInputBegan)

seat.ChildRemoved:Connect(function(child)
	if child.Name == "SeatWeld" then
		local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
		if player ~= nil then

		end
	end
end)
1 Like