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)