Script causing crash?

I’m working on a feature for my Backrooms game that allows me to easily film trailers and made this script to allow me and only me to open the UI to use it, but for some reason the addition of this script causes the game to immediately crash.

input = script.Parent
plrID = game.Players.LocalPlayer.UserId
enabled = false
inputService = game:GetService("UserInputService")

if plrID == 656329197 then
	enabled = true
else
	script:Destroy()
end

while enabled do
	inputService.InputBegan:Connect(function(inputObject)
		if inputObject.KeyCode == Enum.KeyCode.T then
			input.Visible = true
		end
	end)
end

Anyone know what’s wrong?

You are connecting to InputBegan when enabled is set to true, instead you might just want to check when t is pressed if enabled is true.

Try this :

input = script.Parent
plrID = game.Players.LocalPlayer.UserId
enabled = false
inputService = game:GetService("UserInputService")

if plrID == 656329197 then
	enabled = true
else
	script:Destroy()
end

inputService.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.T and enabled == true then
		input.Visible = true
	end
end)
input = script.Parent
plrID = game.Players.LocalPlayer.UserId
inputService = game:GetService("UserInputService")

if plrID == 656329197 then
	inputService.InputBegan:Connect(function(inputObject)
		if inputObject.KeyCode == Enum.KeyCode.T then
			input.Visible = true
		end
	end)
else
	script:Destroy()
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.