This script isn't working

Why is this script not working? It’s supposed to be if the player has the red soda, then it will print something (I will add the other code myself.)

local CD = Instance.new("ClickDetector")
CD.Parent = game.Workspace.Stove.Heat1Clicker

CD.MouseClick:Connect(function(player)
	EB_clickedPlayer = player
	local Backpack = EB_clickedPlayer.Backpack
	local Red = EB_clickedPlayer.Backpack:WaitForChild("Red Soda")
	if EB_clickedPlayer.Backpack:WaitForChild("Red Soda") then
			print("a")
	end
end)

in the if statements dont work the wait for child function so try using find fisrt child function like this:

if EB_clickedPlayer.Backpack:FindFistChild("Red Soda") then

Output is still saying error on line seven.

@joso555 I know, I fixed it though. Still doesn’t work.

remove the Red Variable [Char Limit]

if EB_clickedPlayer.Backpack:FindFirstChild("Red Soda") then

I miss the r

try Findfirstchild like mentioned above this is cleaner version of your code. you don’t need to set all those extra varaibles

local CD = Instance.new("ClickDetector", game.Workspace.Stove.Heat1Clicker)

CD.MouseClick:Connect(function(player)
	local RedSoda = player.Backpack:FindFirstChild("Red Soda")  -- just try to find if not there then RedSoda will be nil
	if RedSoda then
		print("Found RedSoda")
	else
		print("Cant Find RedSoda")
	end
end)

or you could just do

local CD = Instance.new("ClickDetector")
CD.Parent = game.Workspace.Stove.Heat1Clicker

CD.MouseClick:Connect(function(player)
	EB_clickedPlayer = player
	local Backpack = EB_clickedPlayer.Backpack
	local Red = EB_clickedPlayer.Backpack:FindFirstChild("Red Soda")
	if Red then
			print("a")
	end
end)

Thank you so much! It works.
chars

1 Like

hi, i propuse that solution so can u please mark this as solved :smiley: