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

Console system doesn't work and gives no errors?

Asked by 2 years ago
Edited 2 years ago

I want to make a system that checks whether the player has the specific item, and if the player does, then the console would "work". However, the code didn't give me errors and it doesn't work.

Also, I don't really know how to exactly make a system that only destroys the tool if the player pressed the proximity prompt again. For now, it instantly destroys it if the player picks it up after pressing it. (Edit: turns out the textlabel also doesn't work for some reason)

local proxPrompt = script.Parent.ProximityPrompt

proxPrompt.Triggered:Connect(function(touched)
    local backpack = touched:FindFirstChild("Backpack")
    local backpackGame = backpack:WaitForChild("game")
    if backpackGame then
        backpackGame:Destroy()
    elseif backpackGame == nil then
        local cantInsertItemGui = game.StarterGui.CantInsertItemGui
        local textLabel = cantInsertItemGui.TextLabel
        textLabel.Visible = true
        textLabel.Text = "you need a game to play on the console"
    end
end)
0
im not sure why your using WaitForChild instead of FindFirstChild but try putting an amount of seconds to wait for as a second parameter in WaitForChild because i think its infinitely yielding enzotinman1 23 — 2y
0
The FindFirstChild fix worked for the everything before "elseif", thanks. (I didn't point out the textlabel was not working at first.) YeBeaseT21 0 — 2y
0
oof I hate it when there is not a error. xxaxxaz 42 — 2y
0
is this local or not local? xxaxxaz 42 — 2y
View all comments (3 more)
0
xxaxxaz is once again wrong in his answer. the reason this doesnt work is because game.StarterGui isn't the playergui, StarterGui clones and goes in each player --> playergui. This explains no errors. greatneil80 2647 — 2y
0
ah okay thanks, ill try it soon and hope it works YeBeaseT21 0 — 2y
0
thanks everyone, the tips you gave me really helped with the script. YeBeaseT21 0 — 2y

1 answer

Log in to vote
0
Answered by
xxaxxaz 42
2 years ago

this needs two scripts, one local and one not local

not local script:

local proxPrompt = script.Parent.ProximityPrompt

proxPrompt.Triggered:Connect(function(touched)
      local backpack = touched:FindFirstChild("Backpack")
       local backpackGame = backpack:WaitForChild("game")
      if backpackGame then
            backpackGame:Destroy()
    end
end)

local script:

local proxPrompt = script.Parent.ProximityPrompt

proxPrompt.Triggered:Connect(function(touched)
    if backpackGame == nil then
        local cantInsertItemGui = game.StarterGui.CantInsertItemGui
        local textLabel = cantInsertItemGui.TextLabel
        textLabel.Visible = true
        textLabel.Text = "you need a game to play on the console"
    end
end)
Ad

Answer this question