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)
5 comments
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
k thx im dumb
actually it worked before idk why not now
nvm
it didnt work it just does nothing and no error