Find the ducks script wont work

I am trying to make a script that allows you to look for ducks and once you clicked them you get a notification and if you click them again it tells you you already found it. The saving the data when leaving will come later.
Nothing in the output, no results and no notification if i click the ducks.


local clickedDucks = {}

local function handleDuckClick(player, duckName)
	local playerId = player.UserId

	if not clickedDucks[playerId] then
		clickedDucks[playerId] = {}
	end

	if not clickedDucks[playerId][duckName] then
		clickedDucks[playerId][duckName] = true
		player:SendNotification("You found " .. duckName .. "!")
	else
		player:SendNotification("You already found " .. duckName .. "!")
	end
end


game.Workspace.Duck1.ClickDetector.MouseClick:Connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)

	if player then
		handleDuckClick(player, "Duck1")
	end
end)


game.Workspace.Duck2.ClickDetector.MouseClick:Connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)

	if player then
		handleDuckClick(player, "Duck2")
	end
end)

2 Likes

ClickDetector.MouseClick doesn’t return a part; it returns a Player and Player.SendNotification() doesn’t exist.

Also, the reason why there’s no output is because hit.Parent would be Players, so GetPlayerFromCharacter() would always return nil.

1 Like

just make your clickdetector functions like this:

game.Workspace.Duck1.ClickDetector.MouseClick:Connect(function(player)
	handleDuckClick(player, "Duck1")
end)
1 Like