Remote event not sending the right event

I have a script that sends the player through a remote event to a server script but it sends a different player. plr prints the same thing as player.

Script:

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players:FindFirstChild(script.Parent.Text)
	print(player.Name)
	if player then
		game.ReplicatedStorage.Remotes.InvitePlayer:FireServer(plr, player)
	end
end)

Change:
game.ReplicatedStorage.Remotes.InvitePlayer:FireServer(plr, player)
to
game.ReplicatedStorage.Remotes.InvitePlayer:FireServer(player)

When firing the server from the client, the .OnServerEvent automatically retrieves which player sent the request.

Will this script work aswell, it uses the variable you removed, do I have to do any changes?

Server Script:

game.ReplicatedStorage.Remotes.InvitePlayer.OnServerEvent:Connect(function(plr, player)
	print(player.Name.. 'Person invited to party')
	print(plr.Name.. 'Party owner')
	local clone = game.ReplicatedStorage.Invited:Clone()
	clone.Parent = player.PlayerGui.Party
	clone.JoinParty.Text = plr.Name.. ' has invited you to a party'
	local image = game:GetService('Players'):GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size48x48)	
	clone.PlayerImage.Image = image
	clone.Timer.Visible = true
	clone:SetAttribute('Player', plr.Name)
	for i = 1, 45 do
		wait(0.04)
		local formula = i/50
		clone.Timer:TweenSize(UDim2.new(formula, 0, 0.05, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, true)
	end
	clone:Destroy()
end)

It will work :smiley: ! As long as you intend that the plr parameter is the player who sent clicked the button/sent the request, you are good.

For more info you can look here, but I think you should be fine!

Thank you for the help! This will also help me in future development too!

1 Like