Plr is not valid member of players

Hi,
i tried this same script in PlayerGui and click detector but it doesn’t work for some reason:

script.Parent.MouseButton1Click:Connect(function(plr)
 local a = Instance.new("WeldConstraint")
 local b = game.ServerStorage.Union:Clone()
 local char = game.Players.plr.Character
 a.Parent = char.Head
 b.Parent = char.Head
 a.Part0 = a
 a.Part1 = b
end)

Error: plr is not valid member of players

Any idea what is the cause of this error?

Nvm fixed it… forgot that i can’t do

game.Player.plr.Character
but i have to do:
plr.Character

It does… the script works now.

Hi, try to change “game.Players.plr.Character” to regular “plr.Character”. This should work because “plr” will automatically detect the player who clicked.