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

Help with If statement?

Asked by
Xl5Xl5 65
8 years ago

This works fine aside from the fact that if "Lunch" tool isn't in the Backpack it does nothing. This is in a GUI, also this is a local script

How can I get this if statement to check if "Lunch" is in the Players Backpack??

this only works if I do have the tool

game.Players.LocalPlayer.Backpack.Lunch:Remove() --- To remove it
rep.Value = rep.Value - 2
s.Dialog.Choice4.Text = "-2 Rep!" 
s.Dialog.Choice1.Visible = false
s.Dialog.Choice2.Visible = false
s.Dialog.Choice3.Visible = false
s.Dialog.Choice4.Visible = true
choosen = thankslunch Write() 
wait()
s:Destroy()

If I don't have the tool this code won't start,

s.Dialog.Choice4.Text = "Don't Have Lunch"
s:Destroy()

The whole function is here;

s.Dialog.Choice4.MouseButton1Click:connect(function()
if game.Players.LocalPlayer.Backpack.Lunch then
game.Players.LocalPlayer.Backpack.Lunch:Remove()
rep.Value = rep.Value - 2
s.Dialog.Choice4.Text = "-2 Rep!"
s.Dialog.Choice1.Visible = false
s.Dialog.Choice2.Visible = false
s.Dialog.Choice3.Visible = false
s.Dialog.Choice4.Visible = true
choosen = thankslunch Write()
wait()
s:Destroy()
elseif game.Players.LocalPlayer.Backpack.Lunch ~= nil then
s.Dialog.Choice4.Text = "Don't Have Lunch"
s:Destroy()
end
end)

Thanks for reading! Please help! I am confused

1
Check for the tool using this: [ if game.Players.LocalPlayer.Backpack:FindFirstChild("Lunch") == nil then ] this will fire if Lunch is not found in the backpack. Hope this helped! minikitkat 687 — 8y
0
Thanks! that worked! :D Xl5Xl5 65 — 8y

Answer this question