I need help with my Script

I have now spent a very long time writing a script that says that if you equip this tool then in the StarterGui the visibility of an object named there in the script is set to true or false:

if script.Parent.Equipped:Connect() then

game.StarterGui.Objectives.Frame.Framel.Objective1.Visible = false

game.StarterGui.Objectives.Frame.Framel.Objective2.Visible = true

end

(This is a localscript in the tool)
But that never works there comes then always something with a nil value and there I wanted to ask if someone has a better script or a better idea to fix this problem.

Is this part of the full script or is it the entire thing? If it’s part of it, mind sending the whole script?

1 Like

This is the local script in the tool (the whole one) to set this to false or true

First off, to access StarterGui you’d need local sgui = game:GetService("StarterGui") somewhere and change that.

Second, if you want a change to happen to a player’s current GUI, then you’d use their PlayerGui instead, so the previous part wouldn’t really matter.

local plr = game:GetService("Players").LocalPlayer
local gui = plr.PlayerGui

Third, you’re using :Connect() wrong, the correct use would be like this:

script.Parent.Equipped:Connect(function()
--script goes here
end)

After applying these fixes, your script should probably look like this:

local plr = game:GetService("Players").LocalPlayer
local gui = plr.PlayerGui

script.Parent.Equipped:Connect(function()
     gui.Objectives.Frame.Frame1.Objective1.Visible = true 
     gui.Objectives.Frame.Frame1.Objective2.Visible = true 
end)

Edit: Noticed what you were trying to do and changed my answer. Sorry if this caused any confusion.

1 Like

if then statements look if something returns a true or not a nil, it proceeds with the code, unless it has an elseif, if it does, it checks through all of them as well.

Equipped:Connect() does not return anything at all, it connects a specific function which will run the code every time a tool was equipped.

Not much information was provided, but if you’re trying to see if a tool is equipped, you could do

if script:IsDescendantOf(workspace) then
    game.StarterGui.Objectives.Frame.Framel.Objective1.Visible = false

    game.StarterGui.Objectives.Frame.Framel.Objective2.Visible = true
end

But if you wanna run the code when the player equips the tool, you can do this:

script.Parent.Equipped:Connect(function()
    game.StarterGui.Objectives.Frame.Framel.Objective1.Visible = false

    game.StarterGui.Objectives.Frame.Framel.Objective2.Visible = true
end)
1 Like

you cant make the starter gui’s frame to visible you gotta make the frame thats in the playerGui to be visible

Tool.Equipped:Connect(function()
   local plrgui = game.Players.LocalPlayer.PlayerGui
PlayerGui.Objectives.Frame.Frame1.Obejective1.Visible = true
 
 PlayerGui.Objectives.Frame.Frame1.Obejective2.Visible = false
  wait()
 
 PlayerGui.Objectives.Frame.Frame1.Obejective1.Visible = false
 
 PlayerGui.Objectives.Frame.Frame1.Obejective2.Visible = true
 
 PlayerGui.Objectives.Frame.Frame1.Obejective2.Visible = false
end)
1 Like

Tool.Equipped is not a boolean but an event, you need to use :Connect, not an if statement

1 Like