Hey does anyone know why this function is firing even tho no player has clicked it (and how to resolve it) ![]()
The idea is every player in the server has a click detector and this single server script (child of serverscriptstorage) handles all of them. But it’s firing without the necessary input, also not passing on the clickDetector as one of the parameters. Im getting the error “attempt to connect failed, passed value is not a function”
for _, player in pairs(game.Players:GetPlayers()) do
local clickDetector = player.Character:WaitForChild("WaltzClick")
clickDetector.MouseClick:Connect(onPlayerClick(player,clickDetector))
end
Here is the function its connecting if its of any more insight.
local function onPlayerClick(player,clickDetector) --player is the player who clicked the clickdetector
local clickDetector = clickDetector
local Player1 = player
local Player2 = game.Players:GetPlayerFromCharacter(clickDetector.Parent)
-- Check if the players are already partners
if Pairs[Player1.Name] == Player2 then
Player1:Chat(Player2.Name .. " is already your partner")
-- Check if the player2 is already paired
elseif Pairs[Player2.Name] ~= nil then
Player1:Chat(Player2.Name .. " is already paired with " .. Pairs[Player2.Name])
-- Ask Player2 to accept the invitation to dance
else
local confirmed = false
local confirmationGui = Player2.PlayerGui:WaitForChild("WaltzStuff").ConfirmationGUI
confirmationGui.Enabled = true
confirmationGui.Accept.MouseButton1Click:Connect(function()
confirmed = true
confirmationGui.Enabled = false
end)
confirmationGui.Decline.MouseButton1Click:Connect(function()
confirmationGui.Enabled = false
end)
while not confirmed do
wait(10)
if not confirmed then
confirmationGui.Enabled = false
end
end
-- If player2 confirms, create a pair
if confirmed then
if Pairs[Player1.Name] ~= nil then
Pairs[Player1.Name] = nil
end
createDictionary(Player1, Player2)
end
end
end
Thanks 4 ur help! ![]()