This script is not working?

I am trying to make a place where you can make a burger. Pretty much I have the code to cook the patty, and then if you have it then click on the prepare board, you will receive the burger itself.

Code1, this is to display the burger so it looks like you made it.
“ShowCB” is a boolean value inside the prepare board.

local show = game.Workspace.PrepareBurger.showCB

while wait() do
	if show then
		script.Parent.Transparency = 0
		wait(2)
		script.Parent.Transparency = 1
	else
		print("not found")
	end
end

Code 2:



	CD.MouseClick:Connect(function(player) 
		print("clicked")
		local display = script.Parent.showCB
		local CB = player.Backpack:FindFirstChild("CookedBurger")
		print("if cb")
		if CB then
			print("if")
			script.Parent.showCB.Value = true
			wait(1)
			script.Parent.showCB.Value = false
		end
	end)

I think you forgot to give us the code

We need the code to help you. .

I am aware, I pressed enter by accident while making it :laughing:

what part isn’t working? what print statements aren’t going off?

replace local show = game.Workspace.PrepareBurger.showcb to local show = game.Workspace.PrepareBurger:FindFirstChild(“showcb”)

1 Like

The burger won’t display when clicked.

Edit: The burger actually displays before it was clicked, the burger disappears less than a second, comes back.

Code 1 should be:

local show = game.Workspace.PrepareBurger:WaitForChild("showCB")

show.Changed:Connect(function(NewValue)
	if NewValue == true then
		script.Parent.Transparency = 0
		wait(2)
		script.Parent.Transparency = 1
	else
		print("not found")
	end
end)

Code 2 should be:

CD.MouseClick:Connect(function(player) 
		print("clicked")
		local display = script.Parent.showCB
		local CB = player.Backpack:FindFirstChild("CookedBurger")
		print("if cb")
		if CB then
			print("if")
			display.Value = true
			wait(1)
			display.showCB.Value = false
		end
	end)

there is no difference between

if show.Value then
or
if show.Value == true then
1 Like

Yes but OP forgot to add .Value, an instance will always be true.

oh yeah replace if show then to if show.Value then

oh, I actually compared this code to relevant code I had in other scripts, guess I do need to add “.Value” thanks everyone!

2 Likes

Consider not using while wait() do because it causes performance issues if you use it too often

alright, what do I replace it with?

1 Like
local show = game.Workspace.PrepareBurger:WaitForChild("showCB")
show.Changed:Connect(function(NewValue)
	if NewValue == true then
		script.Parent.Transparency = 0
		wait(2)
		script.Parent.Transparency = 1
	else
		print("not found")
	end
end)
1 Like

since its an ObjectValue you could connect a .Changed event to check if the value changes like this :

local show = game.Workspace.PrepareBurger.showCB
show.Changed:Connect(function(value)
if show then
		script.Parent.Transparency = 0
		wait(2)
		script.Parent.Transparency = 1
	else
		print("not found")
	end
end)
1 Like