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

Why wont this enable the bool value?

This is a server script btw

pos = script.Parent
Frame = game.StarterGui.PosPicker.Frame
Player = game.Players.LocalPlayer

function pos(clicked)
	Player.Character.IsHomeCenter.Value = true
Frame.Visible = false
end

pos.MouseButton1Down:connect(pos)

1 answer

There are several issues with this. Firstly, Scripts—formally recognized as ServerScripts—aren't meant to operate on the Client, which means they won't run to start with. To control the local machine, we use LocalScripts. Make sure to convert to one.

Secondly, StarterGui is not the container that actually handles the Users' Interfaces, this is simply a Server container meant to preview the UI to the Developer, and load in the UI to the Player when they join. Think of it like StarterPack and Backpack's relationship. To actually reference the real GUI, we need to call PlayerGui.


Final Note:

You'd want to be using the .MouseButton1Click signal in this scenario. This event will launch when the Player releases their left trigger on a GUI, resulting in an actual Click, whilst 1Down will just fire regardless if the trigger is raised. The 1Click signal will also ensure the click occurs within the bounds of the GUIObject.

Lowercase :connect() is deprecated, it is asked of programmers to use :Connect() in further projects.


local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local PosPicker = PlayerGui:WaitForChild("PosPicker")
local Frame = PosPicker:WaitForChild("Frame")

local Pos = script.Parent

local function Pos()
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local IsHomeCenter = Character:FindFirstChild("IsHomeCenter")
	if (IsHomeCenter) then
		IsHomeCenter.Value = true
		Frame.Visible = false
	end
end

Pos.MouseButton1Click:Connect(Pos)

4 comments

0

this script does not work anyways

0

That is because I made a slight reference mistake, something you should've caught. Please try once more.

0

I did see the pospicker mistake

0

Alright, my apologies for the accusation then. Have you converted to a LocalScript?

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