Custom Working Roblox PC

Alright so I started on a small project where I’m making a working computer, it’s going all fine and well but problem is, if the PC is on and it’s unplugged I want it to destroy the screen and replace it with a new one so the user can boot up again, but I’m getting parent property is locked and I’ve been trying for hours and I couldn’t find a solution, if I can’t then I’ll just have to make the pc unable to be unplugged while it’s on
https://gyazo.com/3ed963177dc5bd31c6d2cfc984388bcb

Here is the logic!

function Plugging()
	Plugged = true
	ScreenGUI.Parent = plr.PlayerGui
	Plug:SetPrimaryPartCFrame(game.Workspace.Outlet.CFrame)
	WeldCon = Instance.new("WeldConstraint")
	WeldCon.Parent =  Plug.PrimaryPart
	WeldCon.Part0 = Plug.PrimaryPart
	WeldCon.Part1 = game.Workspace.Outlet
end

function Unplug()
	WeldCon:Destroy()
	Plug:SetPrimaryPartCFrame(game.Workspace.Outlet.CFrame + Vector3.new(0,0,2))
	PCOn = false
	Plugged = false
	print("Unplugged")
	Methods.Tween(Screen, .2, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0, {BackgroundColor3 = Color3.fromRGB(35, 35, 35)})
	Methods.Tween(PC.Power, .5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0, {Color = Color3.fromRGB(218, 133, 65)})
end
2 Likes

When you instantiate the WeldCon variable, it is scoped (and thus only available) in the first function. You would need to define it in the upper scope like WelCon = nil and then set its value in the plug() function. However I would strongly recommend reading through this:

That isnt the problem at all, I’m afraid

It most certainly is the problem, unless youre leaving out some code :wink:

Nah, It’s definitely not the problem thanks though buddy

Good luck accessing variables defined in other scopes then.

Whatever you say buddy, thanks for the effort

no problem. Im sure you know what you’re doing after trying this ‘for hours’ :laughing:

I actually don’t thats why I came on here :joy: :joy: :joy:

Then it would probably help if you posted more of the code. Hard to say what’s wrong without more information.

If you looked at the gyazo I attached to my post youd pretty much be able to see the problem

Pretty sure that is a video, and not code, or am I missing something here?

1 Like

Alright, the problem is that I need the computer to turn off when I unplug it while it’s on, i’ve tried destroying the screengui then I get a locked property error when I parent it back when I plug it again

If something is destroyed, the instance dissapears, meaning you cannot set its parent again. Maybe try setting ScreenGui.Enabled property to true/false.

The thing is if I do that it’ll be the way it was when I destroyed it, I want a completely new UI parented to the monitor, for the illusion of a restart/reboot

Have you tried keeping a clone of the original Gui in a service like ReplicatedStorage. Then when you need a ‘fresh’ version just clone it from there.

I’ve tried that and it still hasnt worked and it tells me the parent is locked somehow

Well that should definately be possible, so maybe you can post some of that code and we can figure out whats going wrong

1 Like

Alright sorry I kind of got a bit heated at the beginning this is driving me crazy

1 Like

here is the full script

local PASSWORD = "fudge"
local USERNAME = "fudge"

local plr = game.Players.LocalPlayer
local char = plr.Character

local ScreenGUI = plr.PlayerGui:WaitForChild("ScreenUI"):Clone()
local Screen = ScreenGUI.Screen
local UNIX = Screen.Version
local loggin = Screen.loggin

local PC = game.Workspace.PC
local Plug = game.Workspace.Plug

local Plugged = false

local PCOn = false

local BootingUp = false



--// Modules
local Methods = require(game.ReplicatedStorage.Functions)

function MakeVisible(stuff)
	for i,v in pairs(stuff) do
		if v then
			v.Visible = true
		end
	end
end

function MakeInvisible(stuff)
	for i,v in pairs(stuff) do
		if v then
			v.Visible = false
		end
	end
end

local UIObjects = {
	
	Username = Screen.Username;
	Password = Screen.Password;
	Login = Screen.Login;
	UsernameSide = Screen.user;
	PasswordSide = Screen.pass;
	
	
}

function CheckUserAndPass()
	if UIObjects.Username.Text == USERNAME and UIObjects.Username.Text == PASSWORD then
		MakeInvisible(UIObjects)
		wait(.5)
		loggin.Text = "Logging, " .. USERNAME .. " In . . ."
		Methods.Tween(loggin, 1, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 5, true, 0, {TextTransparency = 0})
	end
end

function Plugging()
	Plugged = true
	ScreenGUI.Parent = plr.PlayerGui
	Plug:SetPrimaryPartCFrame(game.Workspace.Outlet.CFrame)
	WeldCon = Instance.new("WeldConstraint")
	WeldCon.Parent =  Plug.PrimaryPart
	WeldCon.Part0 = Plug.PrimaryPart
	WeldCon.Part1 = game.Workspace.Outlet
end

function Unplug()
	WeldCon:Destroy()
	Plug:SetPrimaryPartCFrame(game.Workspace.Outlet.CFrame + Vector3.new(0,0,2))
	PCOn = false
	Plugged = false
	print("Unplugged lmfaoooooooooooooooooooooo")
	Methods.Tween(Screen, .2, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0, {BackgroundColor3 = Color3.fromRGB(35, 35, 35)})
	Methods.Tween(PC.Power, .5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0, {Color = Color3.fromRGB(218, 133, 65)})
end

function ChangePowerOnColor()
	Methods.Tween(PC.Power, .5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0, {Color = Color3.fromRGB(82, 124, 174)})
end
	
function BootUp()
	PCOn = true
	BootingUp = true
	Methods.Tween(Screen, 1, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0, {BackgroundColor3 = Color3.fromRGB(255,255,255)})
	UNIX.Visible = true
	Methods.Tween(UNIX, 1, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0 , {TextTransparency = 0})
	wait(3)
	Methods.Tween(UNIX, 1, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0 , {TextTransparency = 1})
	Methods.Tween(Screen, 1, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, false, 0, {BackgroundColor3 = Color3.fromRGB(31, 104, 213)})
	wait(1)
	MakeVisible(UIObjects)
	BootingUp = false
end


UIObjects.Login.MouseButton1Click:Connect(function()
	CheckUserAndPass()
end)


Plug.plugmain.ClickDetector.MouseClick:Connect(function()
	if not Plugged and not PCOn then
		Plugging()
	elseif Plugged and PCOn and not BootingUp then
		Unplug()
	end
end)


PC.Power.ClickDetector.MouseClick:Connect(function()
	if Plugged and not PCOn then
		ChangePowerOnColor()
		BootUp()
	end
end)