Home > Software design >  Proximity prompt an image label change visible not working
Proximity prompt an image label change visible not working

Time:03-10

I'm trying to make it so that when you use a proximity prompt an image label becomes visible but it's not working, how do I fix this?

local proximity = workspace.Cardpack.ProximityPrompt

local proximityPromptService = game.GetService("ProximityPromptService")

proximity.Triggered:Connect(function()

_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible

end)

CodePudding user response:

_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible

This is where your script goes entirely wrong. This is not LUA syntax and is not how programming works. This is actually what you are currently trying to do.

local value = true = false;

Really what you should be doing is creating a reference to the ImageLabel you are trying to set. Then change it's properties. Setting a variable in the global enviroment won't change the ImageLabel's properties.

local ProximityPromptService = game.GetService("ProximityPromptService");

local ImageLabel = workspace.Inventory.Frame.X1;
local Proximity = workspace.Cardpack.ProximityPrompt;


proximity.Triggered:Connect(function()
   ImageLabel.Visible = true;
end)

CodePudding user response:

This seems to be a simple issue which can be solved with a simple solution (granted you know what you're doing). Now here's some things to note:

  • You don't need to use the ;'s you see on almost every line people make. It's not something mandatory and shouldn't be. Though it's good for when you want to have less lines (if it's your preference).
  • You wouldn't want to have 2 ='s on the same line as it's not the correct syntax (as @sl0th has stated), you cannot attempt such a task as it wouldn't even work. You want it to not just change it back to false anyways.
  • As you code this, I don't believe you fully understand how it works, and to make the code you first of all have to understand COMPLETELY or rather fluently how it works. So let's start off with that!

How do we do this? Let's see:

-- Perhaps put the script INSIDE of the Cardpack, and then do it from here.
-- Also, I'm not sure why you've put an "inventory.Frame" here, if it's a screengui then it should go in StarterGui, however if it's a billboardgui then please ignore me.
local Cardpack = script.Parent -- I've added it inside the cardpack as said.
local Prompt = Cardpack.ProximityPrompt
local Label = workspace.Inventory.Frame.X1 -- using the original directory as I don't know how your explorer looks.
local CanBeVisible = false -- if you want to toggle it.

Prompt.Triggered:Connect(function() -- make sure to look up on devforum about this.
    if not CanbeVisible then -- "not CanBeVisible" is equivalent to "CanBeVisible==false".
        CanBeVisible = true
        Label.Visible = true
    else -- if it's true and not false:
        CanBeVisible = false
        Label.Visible = false
    end
end)

This is a more..."Acceptable" way of coding. People have their preferences, but this is generally how I'd do it based on how you did it. IF you don't understand much I'm always here to help, of course! :D

FINAL NOTES:

local A,B = "A", "B" -- you can assign multiple variables on a single line!
A,B = "B", "A" -- and you can also change more than one on the same line too.
local A = "A";print(A) -- that's how ; is used if you want to do more than one thing on the same line (but not done at the the same time on the same line!). ; Seperates the code without needing to add spaces, though adding/casting variables you should stick to using the comma(s) to separate them assigning new values and whatnot.

Also, you don't even need that ProximityPromptService variable as you never even use it! And you can't just do game.GetService(..), you IDEALLY do it as game:GetService(..).

I hope this helped you and if it did, mark this as the answer! Though this is my first time trying to help people I tried my best lol.

  • Related