How can I detect if a bool value is false when the player touches a part

I’m making a gasa4 game and I’m trying to add a shoplifting ending

I have a bool value in the things that you guy in the shop and if you purchase them, it gets ticked to true but if you don’t it stays false

I would put an invisible part outside the entrance of the store to detect if the player leaves the store

so how can I detect if the bool value is false when the player touches the part

(btw the items you buy are tools in your backpack)

1 Like

You can use the Touched event on the part and check if the bool value is false.
part.Touched:Connect(function(hit)
if myBoolValue == false then
– Do something
end
end)

2 Likes

would this detect the tool?
since the bool value is in a tool that the player would be holding

You can use Local p = game.Players.Localplayer.Backpack:WaitForChild(“name of tool”) to detect the tool.

1 Like

whats the local Buy for in line 3

also what’s this for

but will it detect the bool inside of the tool?

the script has to detect if the bool value inside of the tool is set to true when the player touches a part

I have this as a start

local ShopliftTrigger = script.Parent
local p = game.Players.Localplayer.Backpack:WaitForChild("cheese")

ShopliftTrigger.Touched:Connect(function(hit)
	if game.ReplicatedStorage.Tools.Cheese.Purchased = false then
		game.StarterGui.EndingUI.Enabled = true
		game.StarterGui.EndingUI.TextLabel.Text = "Shoplift"
		game.StarterGui.EndingUI.TextLabel1.Text = "Ending"
	end
end)

but the problem is that it clones the tool from replicated storage so it wouldn’t work
also I would probally also so that the ui has to be dissabled if the value is true

Do not use StarterGui for guis. Use PlayerGui.
To make it so the cheese goes to the player backpack, use
Cheese.Parent = game.Players.Localplayer.Backpack — if Cheese is a tool

Also refer to the Roblox Documentation for more references.

1 Like

Also check it in the player’s humanoid in case they are holding it