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

Object not found even though it is in the parent im searching in?

I had a game i worked on a a long time ago and i came back to work on it but there is a random glitch where a clickscript goes into playergui and enables a gui but it says it isnt present.

Script:

script.Parent.ClickDetector.MouseClick:connect(function()
	game.ReplicatedStorage.TextbookNum.Value = 1
	game.Workspace.Baldi.AIScript.Disabled = true
	game.Workspace.GottaSweep.SweepAIScript.Disabled = true
	game.Players:GetPlayers()[1].PlayerGui.YouCanThinkGui.Enabled = true
	game.Players:GetPlayers()[1].PlayerGui.YouCanThinkGui.BackgroundFrame.ModalButton.Visible = true
	game.Players:GetPlayers()[1].PlayerGui.YouCanThinkGui.BackgroundFrame.TextBox.LocalScript.Disabled = false
end)

Proof: image


use [text](url) for links

5 comments

0

If this script is a Server Script then it cannot read the PlayerGui Instances it didn't create, so you'll need to switch to a LocalScript

0

k thx im dumb

0

actually it worked before idk why not now

0

nvm

0

it didnt work it just does nothing and no error

1 answer

GENERAL PRACTICE

Use :WaitForChild() to check that a part exists before changing it.

game.Workspace can be shortened to workspace

game.Players:GetPlayers()[1] will always return the first player in the game alphabetically and not the player who activated the detector.

ISSUES

connect is deprecated in favor of Connect

Server Scripts cannot read from or alter PlayerGui instances unless they created them.

Revised Local Script under StarterGui

local player = game:GetService("Players").LocalPlayer
local part = workspace:WaitForChild("Textbooks"):WaitForChild("Textbook1")
local gui = script.Parent:WaitForChild("YouCanThinkGui")
local frame = gui:WaitForChild("BackgroundFrame")

part.ClickDetector.MouseClick:Connect(function()
	game:GetService("ReplicatedStorage"):WaitForChild("TextbookNum").Value = 1
	workspace:WaitForChild("Baldi"):WaitForChild("AIScript").Disabled = true
	workspace:WaitForChild("GottaSweep"):WaitForChild("SweepAIScript").Disabled = true
	gui.Enabled = true
	frame:WaitForChild("ModalButton").Visible = true
	frame:WaitForChild("TextBox"):WaitForChild("LocalScript").Disabled = false
end)

EDIT

Since some of these are instances in the workspace, you probably want to change them on the Server and not just a single client:

Server Script under "workspace.Textbooks.Textbook1"

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	game:GetService("ReplicatedStorage"):WaitForChild("TextbookNum").Value = 1
	workspace:WaitForChild("Baldi"):WaitForChild("AIScript").Disabled = true
	workspace:WaitForChild("GottaSweep"):WaitForChild("SweepAIScript").Disabled = true
end)

Local Script under StarterGui

local player = game:GetService("Players").LocalPlayer
local part = workspace:WaitForChild("Textbooks"):WaitForChild("Textbook1")
local gui = script.Parent:WaitForChild("YouCanThinkGui")
local frame = gui:WaitForChild("BackgroundFrame")

part.ClickDetector.MouseClick:Connect(function()
	gui.Enabled = true
	frame:WaitForChild("ModalButton").Visible = true
	frame:WaitForChild("TextBox"):WaitForChild("LocalScript").Disabled = false
end)

3 comments

0

script is not in playergui

0

I know the ServerScript is not. Place the LocalScript into the StarterGui and leave the Server Script, but alter it accordingly

0

idk man used to work

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