Ad
Log in to vote
0

Console system doesn't work and gives no errors?

Asked by 4 days ago
Edited 4 days 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 22 — 4d
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 — 4d
0
oof I hate it when there is not a error. xxaxxaz 38 — 4d
0
is this local or not local? xxaxxaz 38 — 4d
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 2465 — 3d
0
ah okay thanks, ill try it soon and hope it works YeBeaseT21 0 — 3d
0
thanks everyone, the tips you gave me really helped with the script. YeBeaseT21 0 — 3d

1 answer

Log in to vote
0
Answered by
xxaxxaz 38
4 days 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