Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this enable the bool value?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
0
this script does not work anyways KronxGoat 50 — 4y
0
That is because I made a slight reference mistake, something you should've caught. Please try once more. Ziffixture 6913 — 4y
0
I did see the pospicker mistake KronxGoat 50 — 4y
0
Alright, my apologies for the accusation then. Have you converted to a LocalScript? Ziffixture 6913 — 4y
Ad

Answer this question